The way I've done it (using the datagrid as I haven't written anything
in asp.net for a while now) is to add an OnEditCommand attribute to
the DataGrid asp tag. This command will call a function in the code
behind.
(Note: Code typed in here, watch for syntax errors)
Asp.net page
<asp:DataGrid ID="dg1" runat="server" OnEditCommand="dg1_Edit">
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="NameOfTextBox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</asp:DataGrid>
Code Behind
public void dg1_Edit(object sender, DataGridCommandEventArgs e)
{
TextBox txt1 = (TextBox)(e.Item.FindControl("NameOfTextBox"));
}
For it to work in a grid view I think you'll have to do something like
the following:
<asp:GridView id="gv1" runat="server" >
<Columns>
<asp:ButtonField ButtonType=Image CommandName="dg1_Edit"/>
</Columns>
</asp:GridView>
On May 20, 1:38 am, MoNiks <[email protected]> wrote:
> Where have you written this code is the matter of concern ?
> I mean in which event ?
>
> On May 19, 6:58 pm, The_Fruitman <[email protected]> wrote:
>
>
>
> > The way I've done it in the past is
> > TextBox txt1 = (TextBox)(e.Item.FindControl("NameOfTextBox"));
>
> > Where e is type DataGridCommandEventArgs
>
> > On May 18, 9:46 pm, ASP_NET <[email protected]> wrote:
>
> > > i am trying to access the value entered in the textbox in gridview.
> > > TextBox ApplicationName = (TextBox)ctlGridView.Rows
> > > [e.RowIndex].FindControl("txtApplnm");
> > > above is the code.
> > > Is it correct? becoz i am still getting value as null.
>
> > > On May 18, 10:37 pm, Cerebrus <[email protected]> wrote:
>
> > > > Oh, really ? You forgot to ask a question !
>
> > > > On May 18, 4:12 pm, ASP_NET <[email protected]> wrote:
>
> > > > > i get null when i try to access the textbox value in the grid.
> > > > > TextBox ApplicationName = (TextBox)ctlGridView.Rows
> > > > > [e.RowIndex].FindControl("txtApplnm");
>
> > > > > ApplicationName.text returns null even though value is added after
> > > > > gridview edit click.- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -