i have gridview control and textbox + button control in page aspx.
i want pass textbox value to gridview by click button.
<asp:GridView ID="gvName" runat="server" ViewStateMode="Enabled">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblName" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and use this code:
protected void btnAddName_Click(object sender, ImageClickEventArgs e)
{
foreach (GridViewRow row in gvName.Rows)
{
if ((Label)row.FindControl("lblName") is Label)
{
((Label)row.FindControl("lblName")).Text = txtName.Text;
}
}
}
but its no ok. 🙁 please help me.
If grid row has label with
idlblName then you will get it from row and you do not need to check it again.Note: If you do not have rows already in thr gridview then you wont be able get the value in label. You need to ensure their are row(s) in grid.