Text from TextBox in DataList

Discussion in 'ASP .Net' started by etam, May 30, 2007.

  1. etam

    etam Guest

    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.
     
    etam, May 30, 2007
    #1
    1. Advertising

  2. etam

    Andy Guest

    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"
     
    Andy, May 30, 2007
    #2
    1. Advertising

  3. etam

    etam Guest

    On 30 Maj, 20:55, "Eliyahu Goldin"
    <> 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?
     
    etam, May 30, 2007
    #3
  4. 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" <> wrote in message
    news:...
    > 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.
    >
     
    Eliyahu Goldin, May 30, 2007
    #4
  5. 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.
    >
    >
     
    =?Utf-8?B?RGF2aWQgQW50b24=?=, May 30, 2007
    #5
  6. 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.
    > >
    > >
     
    =?Utf-8?B?RGF2aWQgQW50b24=?=, May 30, 2007
    #6
  7. You need first get to the item, something like

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


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "etam" <> wrote in message
    news:...
    > On 30 Maj, 20:55, "Eliyahu Goldin"
    > <> 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?
    >
     
    Eliyahu Goldin, May 30, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,966
  2. mintboy
    Replies:
    0
    Views:
    749
    mintboy
    Jan 24, 2006
  3. Replies:
    3
    Views:
    777
    George Ter-Saakov
    Feb 23, 2007
  4. BisMan
    Replies:
    1
    Views:
    404
    Nathan Sokalski
    Jan 19, 2008
  5. BisMan
    Replies:
    0
    Views:
    378
    BisMan
    Jan 19, 2008
Loading...

Share This Page