关于asp:DropDownList SelectedValue方面的问题
我是ASP.NET自学新手,有ASP.NET方面的问题请高手帮助解答一下:在辑编表Info记录时:
如信息表Info中的字段有Id, Title,Area1,Area2,Area3,Area4 ..等;
地区分类有四级:表Category1(国家,对应该字段class1),表Category2(省市,对应该字段class1,class2),表Category3(城市,,对应该字段class1,class2,class3),表Category4(区/县,,对应该字段class1,class2,class3,class4)
当我想编辑表Info中的记录时,选择国家-省-城市-地区 在没有SelectedValue='<%# Bind("Area2") %>'这样的Bind时是可以正确请的,但加了SelectedValue='<%# Bind("Area2") %>'后选择失效,
想请高手帮忙处理一下,我是新手,谢谢了!
没有加SelectedValue='<%# Bind(表Info字段) %>'时是可以选择国家-省-城市-地区 的
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<%-- Area1 ------%>
<asp:DropDownList ID="ddlArea1" AutoPostBack="true" DataSourceID="obsArea1" DataTextField="Class1" DataValueField="Class1" runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea1" TypeName="Category1" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:Parameter Name="claType" DefaultValue="国家" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area2 -------%>
<asp:DropDownList ID="ddlArea2" AutoPostBack="true" DataSourceID="obsArea2" DataTextField="Class2" DataValueField="Class2" runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea2" TypeName="Category2" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area3 --------%>
<asp:DropDownList ID="ddlArea3" AutoPostBack="true" DataSourceID="obsArea3" DataTextField="Class3" DataValueField="Class3" runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea3" TypeName="Category3" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
<asp:ControlParameter Name="class2" ControlID="ddlArea2" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area4 --------%>
<asp:DropDownList ID="ddlArea4" DataSourceID="obsArea4" DataTextField="class4" DataValueField="class4" runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea4" TypeName="Category4" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
<asp:ControlParameter Name="class2" ControlID="ddlArea2" />
<asp:ControlParameter Name="class3" ControlID="ddlArea3" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>
===========================================================
但修改SelectedValue后就不能选择了(如下),选择国家-省-城市-地区 失效,请高手帮助一下,谢谢:
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<%-- Area1 -----%>
<asp:DropDownList ID="ddlArea1" AutoPostBack="true" DataSourceID="obsArea1" DataTextField="Class1" DataValueField="Class1" SelectedValue='<%# Bind("Area1") %>' runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea1" TypeName="Category1" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:Parameter Name="claType" DefaultValue="国家" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area2 ------%>
<asp:DropDownList ID="ddlArea2" AutoPostBack="true" DataSourceID="obsArea2" DataTextField="Class2" DataValueField="Class2" SelectedValue='<%# Bind("Area2") %>' runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea2" TypeName="Category2" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area3 ---------------------------------------------------------------------------------------%>
<asp:DropDownList ID="ddlArea3" AutoPostBack="true" DataSourceID="obsArea3" DataTextField="Class3" DataValueField="Class3" SelectedValue='<%# Bind("Area3") %>' runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea3" TypeName="Category3" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
<asp:ControlParameter Name="class2" ControlID="ddlArea2" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- Area4 ---------------------------------------------------------------------------------------%>
<asp:DropDownList ID="ddlArea4" DataSourceID="obsArea4" DataTextField="class4" DataValueField="class4" SelectedValue='<%# Bind("Area4") %>' runat="server">
</asp:DropDownList>
<asp:ObjectDataSource ID="obsArea4" TypeName="Category4" SelectMethod="SelectByClasses" runat="server">
<SelectParameters>
<asp:ControlParameter Name="class1" ControlID="ddlArea1" />
<asp:ControlParameter Name="class2" ControlID="ddlArea2" />
<asp:ControlParameter Name="class3" ControlID="ddlArea3" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel> --------------------编程问答-------------------- 绑定好后
在后台设置一下SelectedIndex就可以了 绑它做什么
补充:.NET技术 , ASP.NET