accesing controls in code-behind

R

R.A.M.

Hello,
I am learning ASP.NET.
On .aspx page I have a data-list with text-box that I would like to read
during line modification.

<asp:DataList ...
OnEditCommand="Sample_Edit" >
...
<EditItemTemplate>
...
<asp:TextBox ID="SampleEdit" runat="server" />
...
</EditItemTemplate>
...
</asp:DataList>

In code-behind I have:

protected void Sample_Edit(object sender, DataListCommandEventArgs e)
{
...
string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text;
// here problem
...
}

The problem is that although e.Item is fine, FindControl returns null.
Could you help me to programme it correctly?
Thank you !!!
/RAM/
 
R

R.A.M.

I have also tried this way:
Sample =
((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;

and this way:
Sample =
((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;

but it doesn't work, either.
 
R

R.A.M.

OK, I solved. SampleEdit is not accessible before edit mode set.

U¿ytkownik "R.A.M. said:
I have also tried this way:
Sample =
((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;

and this way:
Sample =
((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;

but it doesn't work, either.

U¿ytkownik "R.A.M. said:
Hello,
I am learning ASP.NET.
On .aspx page I have a data-list with text-box that I would like to read
during line modification.

<asp:DataList ...
OnEditCommand="Sample_Edit" >
...
<EditItemTemplate>
...
<asp:TextBox ID="SampleEdit" runat="server" />
...
</EditItemTemplate>
...
</asp:DataList>

In code-behind I have:

protected void Sample_Edit(object sender, DataListCommandEventArgs e)
{
...
string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text;
// here problem
...
}

The problem is that although e.Item is fine, FindControl returns null.
Could you help me to programme it correctly?
Thank you !!!
/RAM/
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top