EditItemTemplate FindControls

Discussion in 'ASP .Net Datagrid Control' started by JJ, Dec 30, 2004.

  1. JJ

    JJ Guest

    Hi,

    What I am trying to do is save the values from the ItemTemplate textboxs,
    which I already do and when I go into Edit mode insert values into textboxs
    in EditItemTemplate. Inserting values into EditItemTemplate is where I get
    the "obj ref not set error". It happens because the event I use now which is
    in the OnEditCOmmand for datagrid can't find the controls in
    EditItemTemplate. So where should I put the FindControl statements in order
    to have this work?

    Thanks,

    JJ
    JJ, Dec 30, 2004
    #1
    1. Advertising

  2. > What I am trying to do is save the values from the ItemTemplate textboxs,
    > which I already do and when I go into Edit mode insert values into textboxs
    > in EditItemTemplate. Inserting values into EditItemTemplate is where I get
    > the "obj ref not set error". It happens because the event I use now which is
    > in the OnEditCOmmand for datagrid can't find the controls in
    > EditItemTemplate. So where should I put the FindControl statements in order
    > to have this work?


    If I understand you correctly, you want to make sure that the values in
    the ItemTemplate are in the TextBoxes in the EditItemTemplate, correct?

    Don't do this programmatically, but rather declaratively. That is,
    imagine in your ASPX page you have:

    <asp:TemplateColumn>
    <ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Foo") %>
    </ItemTemplate>
    <EditItemTemplate>
    ...
    </EditItemTemplate>
    </asp:TemplateColumn>

    In your TextBox in your EditItemTemplate set the Text property to <%#
    DataBinder.Eval(Container.DataItem, "Foo") %>, like:

    <asp:TextBox runat='server' ... Text='<%#
    DataBinder.Eval(Container.DataItem, "Foo") %>' ... />

    hth

    --

    Scott Mitchell [ASP.NET MVP]

    http://www.4GuysFromRolla.com/ScottMitchell
    Scott Mitchell [MVP], Jan 4, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor Hartman

    datagrid edititemtemplate for dates

    Trevor Hartman, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    369
    Trevor Hartman
    Jul 16, 2003
  2. SStory

    Datalist EditItemTemplate

    SStory, Aug 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    496
    SStory
    Aug 19, 2003
  3. Dave
    Replies:
    1
    Views:
    532
  4. Kevin Quigley

    asp:hyperlink in EditItemTemplate

    Kevin Quigley, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Kevin Quigley
    Dec 2, 2003
  5. =?Utf-8?B?TWljaGFlbA==?=

    Using FindControls and Type casting

    =?Utf-8?B?TWljaGFlbA==?=, Apr 26, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,687
    =?Utf-8?B?TWljaGFlbA==?=
    Apr 26, 2006
Loading...

Share This Page