Showing posts with label datalist. Show all posts
Showing posts with label datalist. Show all posts

Monday, March 26, 2012

Text from TextBox in DataList

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.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"
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" <odwrotnie@.gmail.comwrote in message
news:1180544440.132552.296220@.w5g2000hsg.googlegro ups.com...

Quote:

Originally Posted by

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


On 30 Maj, 20:55, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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?
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:

Quote:

Originally Posted by

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


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:

Quote:

Originally Posted by

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:
>

Quote:

Originally Posted by

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.


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" <odwrotnie@.gmail.comwrote in message
news:1180549263.635323.268780@.q66g2000hsg.googlegr oups.com...

Quote:

Originally Posted by

On 30 Maj, 20:55, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

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?
>

Text from TextBox in DataList

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.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" <odwrotnie@.gmail.com> wrote in message
news:1180544440.132552.296220@.w5g2000hsg.googlegroups.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.
>
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"
On 30 Maj, 20:55, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> 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?
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.
>
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:
>
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" <odwrotnie@.gmail.com> wrote in message
news:1180549263.635323.268780@.q66g2000hsg.googlegroups.com...
> On 30 Maj, 20:55, "Eliyahu Goldin"
> <REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> TextBox tb = (TextBox)GradeDataList.FindControl("GradeTextBox");
> Then tb == null :/.
> But still it is strange... Beacause My GradeDataList has many
> GradeTextBoxes. Am I right?
>

Tuesday, March 13, 2012

Textbox action in datalist

I hope this is as simple as I think it is, but for some reason, I cannot see the forest through the trees. On my page I have a datalist that, during edit mode, displays several text boxes for the user to type in. What I want to is poll a database after the user types in a value into say 'TextBox1'. I just cannot figure out the correct path to the TextBox events when it's a part of the DataList Edit section. Any ideas ? Thanks.It took some digging, but I finally figured out the code to access a textbox within a datalist (thanks to all who helped). I have added the code below and attempted to explain what's going on, but I may not have the wording exactly correct.

Dim i As Integer
Dim crt As Control

Find the datalist control on the page
For i = 0 To Me.DataList.Controls.Count 1
Once the datalist is found, find the textbox control within the datalist
For Each crt In Me.DataList.Controls(i).Controls
Establish a connection to the datalist control line
Dim item As DataListItem = Me.DataList.Controls(i)
Find the text box within the row
Dim tbx As System.Web.UI.WebControls.TextBox =item.FindControl("TextBox1")
If (crt.ID = "TextBox1") Then
If tbx.Text = "Hi" Then
tbx.Text = "Hi There"
Else
tbx.Text = "Bye then"
End If
End If
Next
Next