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 = '';");
}