Page 1/7 of 33 common codes in ASP. NET

Source: Internet
Author: User

1. open a new window and send parameters:
Transfer Parameters:
Response. write ("<script> window. open ('*. aspx? Id = "+ this. DropDownList1.SelectIndex +" & id1 = "+... +" ') </script> ")
Receiving parameters:
String a = Request. QueryString ("id ");
String B = Request. QueryString ("id1 ");
2. Add dialog box for button
Button1.Attributes. Add ("onclick", "return confirm ('OK? ')");
Button. attributes. add ("onclick", "if (confirm ('Are you sure ...? ') {Return true;} else {return false ;}")
3. Delete selected table records
Int intEmpID = (int) MyDataGrid. DataKeys [e. Item. ItemIndex];
String deleteCmd = "Delete from Employee where emp_id =" + intEmpID. ToString ()
4. Delete table record warning
Private void DataGrid_ItemCreated (Object sender, DataGridItemEventArgs e)
{
Switch (e. Item. ItemType)
{
Case ListItemType. Item:
Case ListItemType. AlternatingItem:
Case ListItemType. EditItem:
TableCell myTableCell;
MyTableCell = e. Item. Cells [14];
LinkButton myDeleteButton;
MyDeleteButton = (LinkButton) myTableCell. Controls [0];
MyDeleteButton. Attributes. Add ("onclick", "return confirm ('Are you sure you want to delete this information ');");
Break;
Default:
Break;
}
}
5. Click the table row link to another page.
Private void grdCustomer_ItemDataBound (object sender, System. Web. UI. WebControls. DataGridItemEventArgs e)
{
// Click Open Table
If (e. Item. ItemType = ListItemType. Item e. Item. ItemType = ListItemType. AlternatingItem)
E. Item. Attributes. Add ("onclick", "window. open ('default. aspx? Id = "+ e. Item. Cells [0]. Text + "');");
}
Double-click a table to connect to another page
In the itemDataBind event
If (e. Item. ItemType = ListItemType. Item e. Item. ItemType = ListItemType. AlternatingItem)
{
String orderItemID = e. item. cells [1]. Text;
...
E. item. Attributes. Add ("ondblclick", "location. href = '.../ShippedGrid. aspx? Id = "+ orderItemID + "'");
}
Double-click a table to open a new page.
If (e. Item. ItemType = ListItemType. Item e. Item. ItemType = ListItemType. AlternatingItem)
{
String orderItemID = e. item. cells [1]. Text;
...
E. item. Attributes. Add ("ondblclick", "open ('../ShippedGrid. aspx? Id = "+ orderItemID + "')");
}
6. Table hyperjoin column Transfer Parameters
<Asp: HyperLinkColumn Target = "_ blank" headertext = "id" DataTextField = "id" NavigateUrl = "aaa. aspx? Id ='
<% # DataBinder. eval (Container. dataItem, "data field 1") %> '& name =' <% # DataBinder. eval (Container. dataItem, "data field 2") %> '/>
7. Click to change the color of the table.
If (e. Item. ItemType = ListItemType. Item e. Item. ItemType = ListItemType. AlternatingItem)
{
E. Item. Attributes. Add ("onclick", "this. style. backgroundColor = '#99cc00 ';
This. style. color = 'buttontext'; this. style. cursor = 'default ';");
}
Written in _ ItemDataBound of the DataGrid
If (e. Item. ItemType = ListItemType. Item e. Item. ItemType = ListItemType. AlternatingItem)
{
E. Item. Attributes. Add ("onmouseover", "this. style. backgroundColor = '#99cc00 ';
This. style. color = 'buttontext'; this. style. cursor = 'default ';");
E. Item. Attributes. Add ("onmouseout", "this. style. backgroundColor =''; this. style. color = '';");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.