Hello,
Need someone to show how to get value from gridview column into textbox.
For example if I have "GridViewEmployee" with 4 columns ID, NAME,ADDRESS and EMAIL.
AND ALSO A TEMPLATEFIELD, IN TEMPLATEFIELD ONE LINKBUTTON IS PLACES INSIDE ITEMTEMPLATE. WHEN CLICK ON LINK BUTTON PARTICULAR VALUE FROM GRIDVIEW WILL DISPLAY ON ALL CORRESPONDING TEXTBOXES.
I'm still learning asp.net using C#, and I was trying to do many options, but somehow could not get result.
MY HTML CODE IS
<pre lang="xml"><asp:GridView ID="empGV" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="eid" DataMember="employee" ForeColor="#333333"
GridLines="None" Width="500px">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="eid" HeaderText="Employee Id" />
<asp:BoundField DataField="ename" HeaderText="Employee Name" />
<asp:BoundField DataField="eaddress" HeaderText="Employee Address" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:LinkButton ID="lbSelect" runat="server">Edit</asp:LinkButton>
<%----%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
AND CODEBEHIND CODE IS:
This is nearest I was with the code:
textbox1.text = GridViewEmployee.rows[0].cells(ID);
textbox2.text = GridViewEmployee.rows[0].cells(NAME);
textbox3.text = GridViewEmployee.rows[0].cells(ADDRESS);
textbox4.text = GridViewEmployee.rows[0].cells(EMAIL);
or i have also tried this one but both are not working
WHICH CODE I WILL USE "SELECTEDINDEX OR "ITEMCOMMAND" OR ANYTHING ELSE"
SOME TRIAL CODE IS HERE;
protected void empGV_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = empGV.SelectedRow;
textbox1.Text = row.Cells[1].Text;
textbox2.Text = row.Cells[2].Text;
IF ANY HAVE CODE ABOUT GRIDVIEW MANIPULATION USING TEMPLATEFIELD NOT IN BUILT REASYMADE EDIT OR UPDATE TEMPLATE(COMMANDFIELD).
}
Thank you in advance for help to anyone.