Asp. NET 33 kinds of code in common use 1th/7 page _ Practical Tips

Source: Internet
Author: User
1. Open a new window and transfer parameters:
Transfer parameters:
Response.Write ("<script> window.open" (' *.aspx?id= ') +this. dropdownlist1.selectindex+ "&id1=" +...+ "') </script>")
Receive parameters:
String a = Request.QueryString ("id");
String B = Request.QueryString ("Id1");
2. Add a dialog box for the button
BUTTON1.ATTRIBUTES.ADD ("onclick", "return confirm (' Confirm? ')");
Button.attributes.add ("onclick", "If" (Confirm (' Are you sure ...? ')) {return true;} Else{return false;} ")
3. Delete table Selected records
int intempid = (int) Mydatagrid.datakeys[e.item.itemindex];
String deletecmd = "Delete from Employee where emp_id =" + intempid.tostring ()
4. Delete the form 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" (' You are sure you want to delete this message '); ");
Break
Default
Break
}
}
5. Click on a table row link another page
private void Grdcustomer_itemdatabound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Click on the form to open
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 super Join column pass parameter
<asp:hyperlinkcolumn target= "_blank" headertext= "ID number" 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 form
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 the _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= '; ");
}
Current 1/7 page 1234567 Next read the full text

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.