CheckBoxes Wise Selection In GridView in just 3 steps
1)In ASPX side
your grid view must contain DataKeyNames
and checkbox under templatefield
<asp:GridView ID="GridViewtemp" runat="server" DataKeyNames="Person_Id">
2)Now you have above grid where so many rows are avail and each row has a checkbox in it(as we placed a checkbox in templatefield's item template)
now when user click on these checkboxes and make out his selection we will provide him further a button 'btnselect' which will again bind a grid and show you only those selected row which were checked previously.
3)So On that btnselect_click event
In C# On Button Click
protected void btnselect_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridViewtemp.Rows.Count; i++)
{
if (((CheckBox)GridViewtemp.Rows[i].FindControl("chkSONo")).Checked == true)
{
soid = ((Label)GridViewtemp.Rows[i].FindControl("lblPersonid")).Text;
if (value == "")
{
value = soid;
}
else
{
value = value + "," + soid;
}
}
}
BindItemGrid(soid);
}
public void BindItemGrid(string Key)
{
query = " select * from tb_Stamping where [Person_Id] in (" + value + ")";
SqlDataAdapter adp = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
adp.Fill(ds);
gvselectcontent.DataSource = ds;
gvselectcontent.DataBind();
}
No comments:
Post a Comment