Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net gridview checkbox selection
    primarykey
    data
    text
    <p>Need some help to solve this.</p> <p>I have a gridview and inside the gridview I have a checkbox and after clicking the checkbox, I am doing a postback event and trying to update this particular row only on the database.</p> <p>This is my gridview checkbox code. see the OnCheckedChanged.</p> <pre><code>&lt;asp:TemplateField HeaderText="Sample"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox runat="server" ID="chkSample" Checked='&lt;%# Bind("Sample") %&gt;' OnCheckedChanged="UpdateSupplyLed" AutoPostBack="True"&gt; &lt;/asp:CheckBox&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>Code: </p> <pre><code>protected void UpdateSupplyLed(object sender, EventArgs e) { foreach (GridViewRow di in SamplingGridView.Rows) { CheckBox chkBx = (CheckBox)di.FindControl("chkSample"); if (chkBx != null &amp;&amp; chkBx.Checked) { //update database logic here. } } } </code></pre> <p>The above code works fine but it is getting me all the checkboxes that are checked irresepective of the one that I just checked. I don't want all of them.</p> <p>How can I get the only one row value that have been just checked. Some of the rows might have been checked already because the status is true for those records and I don't want to update those records.</p> <p>I think I've got my question right!</p> <p>Update: The answer is: </p> <pre><code>protected void UpdateSupplyLed(object sender, EventArgs e) { CheckBox chkSampleStatus = sender as CheckBox; bool sample = chkSampleStatus.Checked; GridViewRow row = chkSampleStatus.NamingContainer as GridViewRow; TextBox txtId = row.FindControl("Id") as TextBox; int id = Int32.Parse(txtId.Text); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload