Text from TextBox in DataList

E

etam

Hi,

i have a DataList with a TextBox added by me:

<asp:DataList ID="GradeDataList" runat="server"
DataKeyField="id" DataSourceID="ProjectsObjectDataSource">
<ItemTemplate>
topic:
<asp:Label ID="topicLabel" runat="server" Text='<%#
Eval("topic") %>'></asp:Label><br />
<asp:TextBox ID="GradeTextBox" runat="server"
Text='<%# Grade(Eval("id")) %>' />
</ItemTemplate>
</asp:DataList>

How can I get text from this TextBox?

Thanks in advance,
Etam.
 
A

Andy

Use the .items collection of the datalist to obtain a reference to
your textbox by name.
Once you have the reference, set the value using the textbox's .Text
property.

ie

myDatalist.items("mytexbox").Text="My new value"
 
E

etam

First get to the item, then to the textbox:
TextBox myTextBox = myItem.FindControl("GradeTextBox") as TextBox;

TextBox tb = (TextBox)GradeDataList.FindControl("GradeTextBox");

Then tb == null :/.

But still it is strange... Beacause My GradeDataList has many
GradeTextBoxes. Am I right?
 
E

Eliyahu Goldin

First get to the item, then to the textbox:
TextBox myTextBox = myItem.FindControl("GradeTextBox") as TextBox;
 
G

Guest

Exactly. This will work for variable of any value type, including enums.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
 
E

Eliyahu Goldin

You need first get to the item, something like

TextBox tb = (TextBox)GradeDataList.Items.FindControl("GradeTextBox");
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top