Reputation: 39
I have gridview output like this .
when I click edit link, I need to pass unitsinstock value should transfer to textbox control. which is present in templatefield.
Here is my c# code:
TextBox tt = (TextBox)GridView1.Rows[i].Cells[3].FindControl("TextBox2").ToString();
TextBox text_ref = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[2].FindControl("TextBox2");
TextBox3.Text = text_ref.Text;
Is there anything wrong? when I debugging e.NewEdtIndex=0
, TextBox3=null
. How to solve this?
Upvotes: 1
Views: 2976
Reputation: 6839
You should use EditItemTemplate
for this. For exemple, this code above will bound the unitsinstock value to unitsinstock copy text box when you edit the row.
Change The SqlDataSource as well:
<UpdateParameters>
<asp:Parameter Name="unitsinstock" Type="Int32" /> /*Put the correcly type here*/
/*other fields*/
</UpdateParameters>
And the GridView:
<asp:TemplateField HeaderText="unitsinstock">
<ItemTemplate>
<asp:label id="labelUnitsinstock" runat="server" text='<%#Eval("unitsinstockActual")%>'>
</asp:label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="unitsinstock copy">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("unitsinstock") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Take a look here for more information Using TemplateFields in the GridView Control
Upvotes: 2