EditItemTemplate FindControls

J

JJ

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
 
S

Scott Mitchell [MVP]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top