Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used runtime checkbox in gridview.Below is my code for that.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.Header)
           {

           }

           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               int i = Convert.ToInt16(ViewState["i"]);
               CheckBox chk = new CheckBox();
               chk.ID = "DynamicCheckBox" + e.Row.Cells[0].Text;
               //chk.Text = e.Row.Cells[3].Text;
               e.Row.Cells[0].Controls.Add(chk);
           }
       }

now, i have to check which checkbox are checked, and those checkbox which are checked do something on that row of gridview on button click event.
how to do this?
Posted
Updated 6-May-13 20:04pm
v2
Comments
Sergey Alexandrovich Kryukov 7-May-13 2:37am    
What is not-a-runtime check-box? :-)
—SA

C#
foreach (GridViewRow grdRow in GridView1.Rows)
{
    if (((CheckBox)grdRow.FindControl("DynamicCheckBox" +grdRow.Cells[0].Text)).Checked)
    { 
          // do something
     }
}
 
Share this answer
 
v2
Comments
Member 9511889 7-May-13 2:27am    
my checkbox status is null,even if i checked the checkbox
Member 9511889 7-May-13 2:27am    
what is problem?
KM Perumal 7-May-13 2:30am    
now try
You can add a jquery click handler for the button.
XML
<pre lang="Javascript">
$('#button').click(function(){
   $('[^=DynamicCheckBox]').each(function(){
      if($(this).is(':checked'){
      //add the attribute of checkbox(you want -- can be the row idx) to a hidden field with a delimiter
      }
   });
});

</pre>

Then in the code behind in button click event split the hidden fields value
and get the values you want
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900