By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Text from TextBox in DataList

P: n/a
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.

May 30 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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"

May 30 '07 #2

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

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"etam" <od*******@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
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.

May 30 '07 #3

P: n/a
On 30 Maj, 20:55, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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?

May 30 '07 #4

P: n/a
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
"etam" wrote:
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.

May 30 '07 #5

P: n/a
Sorry - this made it into the wrong thread...
--
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
"David Anton" wrote:
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
"etam" wrote:
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.
May 30 '07 #6

P: n/a
You need first get to the item, something like

TextBox tb = (TextBox)GradeDataList.Items[i].FindControl("GradeTextBox");
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"etam" <od*******@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
On 30 Maj, 20:55, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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?

May 30 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.