Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckBox is used instead of Edit in GridView
    primarykey
    data
    text
    <p>I have trying to Edit and Update my GridView in bulk. I have generated a <code>CheckBox</code> in the first column of my <code>GridView</code>. It works something like this: If I check a particular row in the <code>GridView</code>, the row gets editable. Like this I can check as many rows I want to edit the <code>GridView</code>. I have given a universal button called UPDATE, once after editing all the rows, and click on this button, the <code>GridView</code> is updated looping in each row checking for CheckBox.Check.</p> <p>The issue I am facing here is that, when I click on any <code>CheckBox</code> in the <code>GridView</code> row, I am not getting <code>TextBox</code>. I am trying to convert <code>Label</code> to <code>TextBox</code> on checking a <code>CheckBox</code> in the <code>GridView</code>.</p> <p>So when I check a row, the text corresponding to <code>Label</code> template for that cell goes invisible according to my program, but fails to get the <code>TextBox</code> with the value of that cell.</p> <p>The code I have tried is this:</p> <pre><code>protected void OnCheckedChanged(object sender, EventArgs e) { bool isUpdateVisible = false; CheckBox chk = (sender as CheckBox); if (chk.ID == "chkAll") { foreach (GridViewRow row in GridView3.Rows) { if (row.RowType == DataControlRowType.DataRow) { row.Cells[0].Controls.OfType&lt;CheckBox&gt;().FirstOrDefault().Checked = chk.Checked; } } } CheckBox chkAll = (GridView3.HeaderRow.FindControl("chkAll") as CheckBox); chkAll.Checked = true; foreach (GridViewRow row in GridView3.Rows) { if (row.RowType == DataControlRowType.DataRow) { bool isChecked = row.Cells[0].Controls.OfType&lt;CheckBox&gt;().FirstOrDefault().Checked; for (int i = 3; i &lt; row.Cells.Count; i++) { row.Cells[i].Controls.OfType&lt;Label&gt;().FirstOrDefault().Visible = !isChecked; if (row.Cells[i].Controls.OfType&lt;TextBox&gt;().ToList().Count &gt; 0)//this condition is not satisfying when I debug the program. what is wrong in this line? { row.Cells[i].Controls.OfType&lt;TextBox&gt;().FirstOrDefault().Visible = isChecked; } if (isChecked &amp;&amp; !isUpdateVisible) { isUpdateVisible = true; } if (!isChecked) { chkAll.Checked = false; } } } } UpdateGrid.Visible = isUpdateVisible; } </code></pre> <p>The aspx code is:</p> <pre><code>&lt;asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataKeyNames="Location_Profile_Name"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;HeaderTemplate&gt; &lt;asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" /&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Location_Profile_Name" SortExpression="Location_Profile_Name"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Location_Profile_Name") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Home_Profile" SortExpression="Label10"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Home_Profile") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("Home_Profile") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt;&lt;/asp:GridView&gt; </code></pre> <p>I have commented the issue I am facing in the program above. Kindly help.</p>
    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.
    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