<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;
}
}
}