Note that there are some explanatory texts on larger screens.

plurals
  1. POChecked checkbox in gridview, in c# codebehind checked property is false
    primarykey
    data
    text
    <p>I have custom upload control. The control has gridview with the uploaded documents and the first column has checkbox for selecting documents I want to delete by clicking Delete button. The upload control is contained in other UserControls almost everywhere in the application and works properly, except at one control. The problem is when I check some document for deleting, when the code executes the checked property of the checkbox is false.</p> <pre><code>&lt;asp:GridView ID="gvFiles" runat="server" AutoGenerateColumns="false" ShowHeader="true" CssClass="DataGrid" Width="100%" OnRowDataBound="gvFiles_RowDataBound"&gt; &lt;HeaderStyle HorizontalAlign="left" CssClass="UploadControlGridHeader" /&gt; &lt;RowStyle CssClass="dlcell" /&gt; &lt;EditRowStyle CssClass="dlsell" /&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Delete"&gt; &lt;ItemStyle Width="8%" HorizontalAlign="Center" /&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="chkFile" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>and this is the delete button event</p> <pre><code>protected void btnDelete_Click(object sender, EventArgs e) { for (int i = 0; i &lt; gvFiles.Rows.Count; i++) { CheckBox chk = (CheckBox)gvFiles.Rows[i].Cells[0].FindControl("chkFile"); if (chk.Checked) { // If file is marked/checked to be deleted // then delete it. DeleteFile(i); } } Session[KEY_VIEWSTATEFILES] = this.FileList; // Repopulate gridview BindToGridView(); // Call command to keep same visible screen. CustomCommandEventArgs command = new CustomCommandEventArgs(COMMAND_FILE_DELETED, null); OnHappyCommand(command); } </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.
    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