繁体   English   中英

如何在page_load的级联设计中选择DropDownList项目

[英]How to select DropDownList items in cascading design on page_load

我的aspx页面上有2个下拉列表,第二个由第一个列表中的选择过滤。

页面加载时,如何预先选择两个下拉列表以及保存在数据库中的数据作为记录,当我在Page_Load上的页面上绑定数据时,它不起作用。

我正在使用ObjectDataSource绑定两个下拉列表。

<asp:DropDownList  ID="ddlStatus" runat="server" Enabled="False"  
 onselectedindexchanged="ddlStatus_SelectedIndexChanged" 
 AutoPostBack="True" Width="100px" DataSourceID="ObjectDataSource1" 
 DataTextField="Status_Desc" DataValueField="Status_Id" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
 OldValuesParameterFormatString="original_{0}" SelectMethod="GetStatusAll" 
 TypeName="MyDALTableAdapters.StatusTableAdapter"></asp:ObjectDataSource>       

<asp:DropDownList ID="ddlSubStatus" runat="server" Enabled="False" 
 EnableViewState="False" Width="230px" DataSourceID="ObjectDataSource2" 
 DataTextField="Sub_Status_Desc" DataValueField="Sub_Status_Id" />

<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
OldValuesParameterFormatString="original_{0}" SelectMethod="GetSubStatusData"
TypeName="MyDALTableAdapters.MyStatusSubGetAllTableAdapter">
<SelectParameters>
 <asp:ControlParameter ControlID="ddlStatus" DefaultValue="-1" Name="StatusId"
 PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
      // How to I select the values stored for this record?
    }
}

protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
    ObjectDataSource2.DataBind();
}

只是在每个DropDownList控件上设置SelectedIndex属性的情况

ddlStatus.SelectedIndex = [your selected index];
ddlSubStatus.SelectedIndex = [your selected index];

我最终将第二个下拉列表绑定到第一个下拉列表的DataBind事件上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM