C# - 中继器中的下拉列表不起作用

C# - Dropdown in repeater not working

protected void LoadRecords()
{
    List<PO.viewSO_Result> viewpolist = objDb.viewSO().ToList();

    CustomerRepeater.DataSource = viewpolist;
    CustomerRepeater.DataBind(); 
}

这是 .aspx 代码:

<asp:Repeater ID="CustomerRepeater" runat="server" >
    <ItemTemplate>
        <tr class="odd gradeX" > 
            <td><%# Eval("Supplier_order_id_pk") %></td> 
            <td>
                <asp:DropDownList runat="server" ID="dropdown1">
                    <asp:ListItem Text='<%# Eval("Supplier_order_id_pk") %>' Value='<%# Eval("Supplier_order_id_pk") %>'></asp:ListItem>
                </asp:DropDownList>
            </td> 
        </tr>
    </ItemTemplate>
</asp:Repeater>

我的 DropDown 不工作或获取值。这是错误消息:

Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ListItem does not have a DataBinding event

我需要使用这种方式在转发器中创建 DropDown。

试试这个

<asp:Repeater ID="CustomerRepeater" runat="server" OnItemDataBound="CustomerRepeater_ItemDataBound">
<ItemTemplate>
    <tr class="odd gradeX" > 
        <td> <asp:Label ID="lblOrderID" runat="server" Text='<%# Eval("Supplier_order_id_pk") %>'></asp:Label></td> 
        <td>
            <asp:DropDownList runat="server" ID="dropdown1">

            </asp:DropDownList>
        </td> 
    </tr>
</ItemTemplate>

protected void CustomerRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList ds = (DropDownList)e.Item.FindControl("dropdown1");
            ds.Items.Add((e.Item.FindControl("lblOrderID") as Label).Text);
        }
    }