【问题标题】:How to access the data in a Dropdown list which is inside a repeater when button is clicked单击按钮时如何访问中继器内的下拉列表中的数据
【发布时间】:2018-05-23 12:15:08
【问题描述】:

我在中继器中有一个下拉列表,其列表项中有数据,当单击中继器内的按钮时,我需要访问所选数据。我的html代码如下

<asp:Repeater runat="server" ID="rptrData"  OnItemCommand="rptrData_ItemCommand">
    <ItemTemplate>
        <tr role="row" class="odd">
            <td>
                <asp:DropDownList ID="ddlProgress" runat="server">
                    <asp:ListItem Value="0">No Basement</asp:ListItem>
                    <asp:ListItem Value="1">Basement</asp:ListItem>
                    <asp:ListItem Value="2">Lintel</asp:ListItem>
                    <asp:ListItem Value="3">Roof</asp:ListItem>
                </asp:DropDownList></td>
            <td>
                <div class="btn-group btn-group-xs">
                    <asp:Button ID="Update" runat="server" Text="Update" UseSubmitBehavior="False" CommandName="Update" />
                </div>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您可以在RepeaterCommandEventArgs 项目上使用FindControl,因为中继器是发送者。

    protected void rptrData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //use findcontrol to locate the DDL and cast it
        DropDownList drp = e.Item.FindControl("ddlProgress") as DropDownList;
    
        //show result
        Label1.Text = drp.SelectedValue;
    }
    

    请注意,ddlProgress 中的所有值都是 0,这可能会导致问题。让它们独一无二。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 2023-03-14
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      相关资源
      最近更新 更多