I am using edit template in my gridview to update some control values like dropdowns, textboxes etc.I am finding these control on update function as follows :
string dd1 = ((DropDownList)OwnerGrid.Rows[e.RowIndex].FindControl("ddl1")).SelectedItem.Text.Trim();
string actual = ((TextBox)OwnerGrid.Rows[e.RowIndex].FindControl("txtowneractual")).Text.Trim();
I have bound dropdowns from which i am selecting items before updating. I am also filling textboxes before updating. The textboxes are not binded.
When I am clicking on update, it is throwing “Object reference not set to instance of an object” error. I have debugged the code, textbox value is null while I am getting dropdown value.
What is the issue ?
Designer for textbox :
<asp:TemplateField HeaderText = "Actual" >
<EditItemTemplate>
<asp:TextBox ID="txtowneractual" Width="80px" runat="server" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
I think your textbox is in Edit Item template due to which you are getting a null reference exception. try some thing like this