saloj
asked on
get the specific checkbox value when the button is clicked on gridview
Hi EE,
I have GridView which has 3 checkboxes column and one button column. some records have all checkboxes are checked, some are just one or two are checked according to the database's check record.
suppose if i just check on the one checkbox and hit the button from the first record then it gets other checkboxes value too on my following code.
How can I get only the same record's selected checkbox value which is hitted.
[.aspx]
<asp:CheckBox ID="CheckBox0" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32( Eval("art_ id")),0) %>' />
<asp:CheckBox ID="CheckBox1" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32( Eval("art_ id")),1) %>' />
.
.
<asp:CheckBox ID="CheckBox5" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32( Eval("art_ id")),5) %>' />
<asp:Button ID="Button1" runat="server" Text="View" CommandName="view" CommandArgument='<%# Eval("art_id")%>'
[.aspx.cs]
protected void GridView1_RowCommand(objec t sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "view") {
foreach (GridViewRow row in GridView1.Rows)
{
artid = e.CommandArgument.ToString ();
CheckBox cb0 = (CheckBox)row.FindControl( "checkBox0 ");
CheckBox cb1 = (CheckBox)row.FindControl( "checkBox1 ");
CheckBox cb2 = (CheckBox)row.FindControl( "checkBox2 ");
CheckBox cb3 = (CheckBox)row.FindControl( "checkBox3 ");
CheckBox cb4 = (CheckBox)row.FindControl( "checkBox4 ");
CheckBox cb5 = (CheckBox)row.FindControl( "checkBox5 ");
if (cb0.Checked)
{
displayID = "0";
}
if (cb1.Checked)
{
displayID = "1";
}
..........
}
}
I have GridView which has 3 checkboxes column and one button column. some records have all checkboxes are checked, some are just one or two are checked according to the database's check record.
suppose if i just check on the one checkbox and hit the button from the first record then it gets other checkboxes value too on my following code.
How can I get only the same record's selected checkbox value which is hitted.
[.aspx]
<asp:CheckBox ID="CheckBox0" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(
<asp:CheckBox ID="CheckBox1" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(
.
.
<asp:CheckBox ID="CheckBox5" runat="server" title="All" Checked='<%# HasRecord(Convert.ToInt32(
<asp:Button ID="Button1" runat="server" Text="View" CommandName="view" CommandArgument='<%# Eval("art_id")%>'
[.aspx.cs]
protected void GridView1_RowCommand(objec
{
if (e.CommandName == "view") {
foreach (GridViewRow row in GridView1.Rows)
{
artid = e.CommandArgument.ToString
CheckBox cb0 = (CheckBox)row.FindControl(
CheckBox cb1 = (CheckBox)row.FindControl(
CheckBox cb2 = (CheckBox)row.FindControl(
CheckBox cb3 = (CheckBox)row.FindControl(
CheckBox cb4 = (CheckBox)row.FindControl(
CheckBox cb5 = (CheckBox)row.FindControl(
if (cb0.Checked)
{
displayID = "0";
}
if (cb1.Checked)
{
displayID = "1";
}
..........
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.mikesdotnetting.com/Article/66/Referencing-CheckBoxes-in-GridView-Repeater-and-DataList-controls
http://www.ezineasp.net/post/ASP-Net-C-sharp-GridView-FindControl-Checkbox.aspx