是否可以将hiddenfield绑定到下拉列表?

时间:2014-02-06 06:13:37

标签: c# asp.net

<asp:DropDownList ID="ddlPackage" runat="server" CssClass="ddlPackage" 
Height="24px" Width="250px">
</asp:DropDownList>

<cc1:listsearchextender id="ddlPackage_ListSearchExtender" runat="server" 
enabled="True" targetcontrolid="ddlPackage">
</cc1:listsearchextender>

<asp:Label ID="lblPackage" runat="server" CssClass="errormsg" 
Style="color: Red; display: none;"></asp:Label>

<asp:HiddenField ID="hdnNewOldType" runat="server" 
Value='<%#Bind("NewOldType") %>' />

是否可以将hiddenfield绑定到下拉列表?

1 个答案:

答案 0 :(得分:0)

如果DataTable中有3列:

  • 名称
  • 类型

如果您想根据所选代码检查类型,那么您可以使用下面提到的 SelectedIndexChanged 事件下拉列表:

下拉列表代码:

<asp:DropDownList ID="ddlPackage" runat="server" CssClass="ddlPackage"
    Height="24px" Width="250px" OnSelectedIndexChanged="ddlPackage_OnSelectedIndexChanged">
</asp:DropDownList>

代码背后:

protected void ddlPackage_OnSelectedIndexChanged(object sender, EventArgs e)
{
    var selectedCode = this.ddlPackage.SelectedValue;

    // Code to check type for selectedCode
}