SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ListView, DropdownList & DataBind

    I have a form that has a Dropdown list box and few text boxes etc.
    The form is inside ListView control and I am using DataBind to bind data with text boxes and drop down list.

    To give you an idea, I have simplified the code and it looks like this:
    HTML Code:
                  <asp:ListView ID="ContactSupport" runat="server" OnPreRender="ContactSupport_PreRender">
                      <ItemTemplate>
                          <tr>
                            <td><asp:TextBox ID="txtNetworkProvider" runat="server" Text='<%#Eval("txtNetworkProvider") %>'></asp:TextBox></td>
                            <td><asp:DropDownList ID="txtTypeOfLine" runat="server" >
                            <asp:ListItem Text="A" Value="A"></asp:ListItem>
                            <asp:ListItem Text="12" Value="12"></asp:ListItem>
                        </asp:DropDownList></td>
                          </tr>
                      </ItemTemplate>
                  </asp:ListView>
    ContactSupport_PreRender code behind:
    HTML Code:
                    ContactSupport.DataSource = ds.Tables["Records"];
                    ContactSupport.DataBind();
    Problem:
    Data binding with text box controls works fine, but what should I do to bind data with dropdown list box?

    Note that there are several other text boxes in the form and I just simplified the above code. A screenshot of form is attached below
    screenshotphone.gif

  2. #2
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any solution to it?

  3. #3
    Community Advisor ULTiMATE's Avatar
    Join Date
    Aug 2003
    Location
    Bristol, United Kingdom
    Posts
    2,160
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    What are you trying to bind to your DropDownList object? All you need is a collection of strings (i.e. List<String>) and to bind it like so:

    Code:
        foreach (string str in stringList){
            dropDownListobject.Items.Add(new ListItem(stringList[str]));
        }

  4. #4
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not trying to add items to dropdown.
    Please have a look at the screenshot I attached with my question and read the details.

  5. #5
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    See the following which is what I'm assuming you're looking for as your question was very vague, you haven't really explained how you want to bind the data and when it's bound.

    http://www.codeproject.com/Questions...st-with-csharp

  6. #6
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your response.
    I am new to ASP.net and still learning different terms etc.

    This is the online form of a telephone company, where a user may request to add more than one telephone lines. The form has text boxes as well as a dropdown box.

    I am using ListView to display list of telephone line requests from a user and binding data with it on "OnPreRender"

    Code:
    <asp:ListView ID="ContactSupport" runat="server" OnPreRender="ContactSupport_PreRender">
                      <ItemTemplate>
                          <tr>
                            <td><asp:TextBox ID="txtNetworkProvider" runat="server" Text='<%#Eval("txtNetworkProvider") %>'></asp:TextBox></td>
                            <td><asp:DropDownList ID="txtTypeOfLine" runat="server" >
                            <asp:ListItem Text="A" Value="A"></asp:ListItem>
                            <asp:ListItem Text="12" Value="12"></asp:ListItem>
                        </asp:DropDownList></td>
                          </tr>
                      </ItemTemplate>
                  </asp:ListView>
    Code:
     ContactSupport.DataSource = ds.Tables["Records"];
                    ContactSupport.DataBind();
    The binding works fine for textboxes, but I could not find a way to bind data with dropdowns.

    Please help.
    Last edited by itHighway; Oct 30, 2013 at 07:37. Reason: added more info


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •