小编s.e*_*s.e的帖子

下拉列表重置SelectedValue

我有一个连接到ObjectDataSource的DropDownList.在我的页面加载中,我根据具体情况将s​​electedvalue设置为特定值.如何在我的方法中选择索引以"重置"所选值,以便您仍然可以从其他选项中进行选择?或者我不应该使用selectedvalue来设置下拉列表的默认值?

 <asp:DropDownList ID="DropDownList" runat="server" DataSourceID="ObjectDataSource" DataTextField="Type" DataValueField="TypeId" 
    AutoPostBack="true" onselectedindexchanged="DropDownList_SelectedIndexChanged" >
            </asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
{
        int default = category.TypeId;
        DropDownList.SelectedIndex = default;

}

protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{

    int id = int.Parse(DropDownList.SelectedValue);
    Session["id"] = id;
}
Run Code Online (Sandbox Code Playgroud)

asp.net selectedvalue drop-down-menu

4
推荐指数
2
解决办法
4万
查看次数

标签 统计

asp.net ×1

drop-down-menu ×1

selectedvalue ×1