Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't reach a control from EditItemTemplate in a GridView
    primarykey
    data
    text
    <p>I can't find the controls I want when trying to update my gridview. The controls are textboxes and a dropdownlist from an EditItemTemplate. However, if I try to find a label in ItemTemplate it works just fine. The problem seem to be that it "jumps out" of edit mode before I have a chance to get the controls.</p> <p>Markup for my gridview:</p> <pre><code>&lt;asp:GridView ID="ProductGridView" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" OnRowEditing="ProductGridView_RowEditing" OnRowCancelingEdit="ProductGridView_RowCancelingEdit" OnRowUpdating="ProductGridView_RowUpdating" OnRowDeleting="ProductGridView_RowDeleting" OnRowDataBound="ProductGridView_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CausesValidation="false" /&gt; &lt;asp:TemplateField HeaderText="Name" SortExpression="Name"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="txtName" runat="server" Text='&lt;%# Bind("Name") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblName" runat="server" Text='&lt;%# Eval("Name") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Quantity" SortExpression="Quantity"&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="txtQuantity" runat="server" Text='&lt;%# Bind("Quantity") %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblQuantity" runat="server" Text='&lt;%# Eval("Quantity") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Family" SortExpression="Family.Name"&gt; &lt;EditItemTemplate&gt; &lt;asp:DropDownList ID="ddlFamily" runat="server" OnInit="ddlFamily_Init"&gt; &lt;/asp:DropDownList&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblFamily" runat="server" Text='&lt;%# Eval("Family.Name") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>This is the code-behind from my RowUpdating method. How do I reach the controls from the EditItemTemplate? Am I missing something really simple?</p> <pre><code>protected void ProductGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Get the controls GridViewRow row = ProductGridView.Rows[e.RowIndex]; Label lblName = (row.FindControl("lblName") as Label); // Returns this label, from the row being edited, just fine TextBox txtName = (row.FindControl("txtName") as TextBox); // null TextBox txtQuantity = (row.FindControl("txtQuantity") as TextBox); // null DropDownList ddlFamily = (row.FindControl("ddlFamily") as DropDownList); // null // More code to populate product etc. } protected void ProductGridView_RowEditing(object sender, GridViewEditEventArgs e) { ProductGridView.EditIndex = e.NewEditIndex; BindGridView(_productRepo.GetAll()); } </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