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. Advertisements

  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. Advertisements

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:
    447
    Trevor Hartman
    Jul 16, 2003
  2. SStory

    Datalist EditItemTemplate

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

    asp:hyperlink in EditItemTemplate

    Kevin Quigley, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    457
    Kevin Quigley
    Dec 2, 2003
  5. Gene McCrory
    Replies:
    5
    Views:
    4,329
    Yan-Hong Huang[MSFT]
    Dec 12, 2003
  6. VB Programmer
    Replies:
    2
    Views:
    740
    VB Programmer
    Apr 8, 2004
  7. =?Utf-8?B?bWc=?=
    Replies:
    1
    Views:
    728
    Ashish M Bhonkiya
    May 18, 2004
  8. =?Utf-8?B?TWljaGFlbA==?=

    Using FindControls and Type casting

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