Use ViewState to save the value of the previous checkbox tick when you page over ASP.

Source: Internet
Author: User

<summary>
CheckBox Tick Uncheck Event
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
protected void checkboxl_oncheckedchanged (Object sender, EventArgs e)
{
String tempvalue = String. empty;//splicing The temporary variables of the Federated primary key
var checkbox = sender as checkbox;
GridViewRow row = (gridviewrow) checkbox. namingcontainer;//Get Row properties
Label Lbsno = (label) row. FindControl ("SNo");
Label Lbitemno = (label) row. FindControl ("ItemNo");

if (checkbox. Checked)//tick
{
viewstate["Retuvalue"] + = lbSNo.Text.ToString () + "," + Lbitemno.text + ";";
}
else//Uncheck the check box
{
When unchecked, turn viewstate["Retuvalue" to the collection to remove items from viewstate["Retuvalue"]
list<string> templist = viewstate["Retuvalue"]. ToString (). TrimEnd (';'). Split (';'). ToList ();
for (int i = 0; i < templist. Count; i++)
{
if (Templist[i]. ToString () = = lbSNo.Text.ToString () + "," + Lbitemno.text)
{
Templist. Remove (Templist[i]);
i--;
Continue
}
Tempvalue + = Templist[i] + ";"; /splicing again
}
viewstate["Retuvalue"] = Tempvalue;

}
}

Air bound events
protected void Gvdata_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (viewstate["Retuvalue"]! = NULL)
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
CheckBox check = (checkbox) e.row.cells[10]. FindControl ("Checkboxl");
Get two primary keys stitched into a string
Label Lbsno = (label) E.row.findcontrol ("SNo");
Label Lbitemno = (label) E.row.findcontrol ("ItemNo");
if (viewstate["Retuvalue"]. ToString (). TrimEnd (';'). Contains (lbSNo.Text.ToString () + "," + Lbitemno.text))
{
Check. Checked = true;
}
}
}

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.