Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fredrik Esseen 594 posts 830 karma points
    Nov 09, 2010 @ 13:02
    Fredrik Esseen
    0

    Use Dropdownlist as datasource

    I have a problem which is not really Umbraco-related but hopefully I casn get some help anyhow :).

    I have a dropdownlist control that I use to populate a repeater. I managed to get it to work just fine but i must have changed the code somehow because not its not working.

    I want to get the Value from the dropdownlist and the Text.

    My Repeater looks like this:

     

    <asp:Repeater ID="Repeater1" runat="server">

     

    <HeaderTemplate>

     

    <table class="grid">

     

    <thead>

     

    </thead>

     

    <tbody>

     

    </HeaderTemplate>

     

    <ItemTemplate>

     

    <tr id='<%# Container.DataItem, "Value" %>'>

     

    <td>

     

    <asp:Label Text='<%# Container.DataItem %>' runat="server"></asp:Label>

     

    </td>

     

    </tr>

     

    </ItemTemplate>

     

    <FooterTemplate>

     

    </tbody> </table>

     

    </FooterTemplate>

     

    </asp:Repeater>

    And my code for populating it:

     

    DropDownList dl = new DropDownList();

     

     

    foreach (string NodeID in nodearr)

    {

     

    var theNode = new Node(Convert.ToInt32(NodeID));

     

    ListItem li = new ListItem();

    li.Value = theNode.Id.ToString();

    li.Text = theNode.Name;

    dl.Items.Add(li);

    }

     

    Repeater1.DataSource = dl.Items;

    Repeater1.DataBind();

    The problem is in the repeater when i try to get the Value.

    <

     

    tr id='<%# Container.DataItem, "Value" %>'>

     

    I thought that this way to get the value was ok but it seems that this is not working.

    What am I doing wrong?

  • Fredrik Esseen 594 posts 830 karma points
    Nov 09, 2010 @ 13:23
    Fredrik Esseen
    0

    As usual when I post at this forum I found the solutions right afterward..

    I added this:

     

    dl.DataTextField =

    "Text";

    dl.DataValueField =

    "Value";

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies