两个下拉框的问题? 当一个下拉框的值发生改变时另一个也发生变化并且数据都是在数据库中就是当一下拉框选取一个表的外键时,另一个下拉框显示主键要求不能闪屏 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最简单的就是你直接用微软的ajax控件,UpdatePanle就可以搞定了。把两个DropDownList直接放进去,就OK了。 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"> </asp:DropDownList></div> </form></body></html>using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls; using System.Data.OleDb;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {if (! IsPostBack ){ //binding the dropdown list box //test use a staring arry string[] s1= new string[]{"11-----","12------","13------",}; string[] s2= new string[]{"21-----","22------","23------",}; DropDownList1.DataSource = s1; DropDownList1.DataBind(); //select chose if (ViewState["list1"] != null) { ListItem item =(ListItem)ViewState["list1"] ; foreach (ListItem it in DropDownList1.Items ){ if (item.Text == it.Text) { it.Selected = true; break; } } }DropDownList2.DataSource = s2;//可根据S1情况进行绑定 DropDownList2.DataBind(); //select chose if (ViewState["list2"] != null) { ListItem item = (ListItem)ViewState["list2"]; foreach (ListItem it in DropDownList2.Items) { if (item.Text == it.Text) { it.Selected = true; break; } } } } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { ViewState["list1"] = DropDownList1.SelectedItem.Text; } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { ViewState["list2"] = DropDownList1.SelectedItem.Text; }} DataTable进行汇总 大家过来看看咯。 C#怎样写自己的的集合呢? web版wpf开发中关于datagrid操作! datagirdview 分页 如何让 datagrid 的sex 列显示为 “男” 或 “女”? winform可以在运行的时候带参数执行吗? 求字符串的全排列 Sql数据库主键问题,很简单的. 求救!关于窗口传值 如何让程序自己判断是Insert 还是 Update? 关于多线程同时运行的问题
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList></div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls; using System.Data.OleDb;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostBack ){ //binding the dropdown list box //test use a staring arry
string[] s1= new string[]{"11-----","12------","13------",}; string[] s2= new string[]{"21-----","22------","23------",}; DropDownList1.DataSource = s1;
DropDownList1.DataBind();
//select chose
if (ViewState["list1"] != null) {
ListItem item =(ListItem)ViewState["list1"] ;
foreach (ListItem it in DropDownList1.Items ){ if (item.Text == it.Text) { it.Selected = true;
break;
}
}
}DropDownList2.DataSource = s2;//可根据S1情况进行绑定
DropDownList2.DataBind();
//select chose
if (ViewState["list2"] != null)
{
ListItem item = (ListItem)ViewState["list2"];
foreach (ListItem it in DropDownList2.Items)
{ if (item.Text == it.Text)
{ it.Selected = true;
break; }
} } } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["list1"] = DropDownList1.SelectedItem.Text; }
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["list2"] = DropDownList1.SelectedItem.Text; }
}