page_load级联设计中如何选择DropDownList项
我的 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();
}
I have 2 dropdownlists on my aspx page, second is filtered by the selection in the first list.
How do I pre-select the two dropdown lists with the data saved in the database for the record when the page loads, it does not work when I bind data on the page on Page_Load.
I am using ObjectDataSource to bind the two dropdownlists.
<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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该只是设置 SelectedIndex 属性
it should just be a case of setting the SelectedIndex property on each DropDownList control
我最终将第二个下拉列表绑定到第一个下拉列表的 DataBind 事件上。
I ended up binding the second dropdownlist on the DataBind event of the first dropdownlist.