Tips for using several standard controls in ASP. net2.0

Source: Internet
Author: User

Leave a record for yourself
1. Add a confirmation page to the delete button
Add a confirmation window for the common button and linkbutton. You only need to write "Return confirm" in their onclickclient attribute ('Are you sure you want to delete this project? . You can add a delete button in the templatefield of the gridview and detailsview controls in the same way, however, if you use the autogeneratedeletebutton = "true" generated by detailsview, how does one add this confirmation window? Because we cannot set the attributes of the automatically generated delete button in the design window, we can find a method in a circle on the Internet:
Write the following code in the itemcreated event of detailsview:

Protected void detailsviewtips_itemcreated (Object sender, eventargs E)
{
// Test footerrow to make sure all rows have been created
If (detailsviewtips. footerrow! = NULL)
{
// The command bar is the last element in the rows collection
Int commandrowindex = detailsviewtips. Rows. Count-1;
Detailsviewrow commandrow = detailsviewtips. Rows [commandrowindex];

// Look for the delete button
Datacontrolfieldcell cell = (datacontrolfieldcell) commandrow. controls [0];
Foreach (control CTL in cell. Controls)
{
Linkbutton link = CTL as linkbutton;
If (Link! = NULL)
{
If (link. commandname. tolower () = "delete ")
{
Link. tooltip = "Click here to delete ";
Link. onclientclick = "Return confirm ('Do you really want to delete this record? ');";
}
}
}
}
}

2. pagination of the gridview
If the performanceid is specified in the gridview, you do not need to do anything, and all paging and sorting can be well implemented by yourself. However, if you use the gridview by yourself. datasource = source; gridview. databind (); to bind it by yourself, you have to implement the pageindexchanging event of the gridview by yourself. The code is roughly this protected void gridvieweditor_pageindexchanging (Object sender, gridviewpageeventargs E)
{
Datatable source = ..;
Gridview. datasource = source;
Gridview. pageindex = E. newpageindex;
Gridview. databind ();
}

3. Verification of controls during editing of detailsview
To use the verification control, the verification control in detailsview can only be in its templatefield, and the verification control in each templatefield can only find textbox and other controls in the same templatefield. If you want to boast field verification, you can only use the customvalidator control, and then implement its customvalidator1_servervalidate event with similar Code as follows:

Protected void customvalidator1_servervalidate (Object source, servervalidateeventargs ARGs)
{
Textbox TB = (textbox) detailsvieweditor. findcontrol ("textboxgpsw ");
String psw1 = Tb. text;
TB = (textbox) detailsvieweditor. findcontrol ("textboxpassword ");
String psw2 = Tb. text;
If (psw1 = psw2)
{
Args. isvalid = true;
}
Else
{
Args. isvalid = false;
}
}
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.