dropdownlist 通过数据库绑定 我要实现(比如说:在第一个dropdownlist1 中选择“计算机软件类”在dropdownlist2相应的出现子类:软件工程师 软件测试员 价架构师等;如果在dropdownlist1选择“经营管理类”在dropdownlist2 相应出现“总监、营销经理……”等等)数据库中我设计“计算机软件类”的列名(ID)为1,相应的“软件工程师 软件测试员 价架构师”也对应为1 望各位多多指点!
解决方案 »
- 求asp.net原理的书籍
- asp.net 如何!动态!自定义扩展属性及相关(反射?)
- 如何控制GridView控件中的 imagefiled 图片显示的大小?
- 100求解 vs2005水晶报表问题 在线等 急啊。。。 解决马上给分!
- 在vs2005 中 新建一个 aspx 页面,总是默认的XHTML标准,
- 如何在c#中post参数给一个php页面
- dropdownlist求助
- datagrid控件,如何一行放2条记录
- 在DataGrid控件中设置权限?
- 动态生成XML里为什么路径不可以有&这个号
- 在html文件中,用js获取session?
- VSS2005的问题 怎么把多个项目设置在一个VSS里面 还有就是登陆的时候为什么别人不输入用户名和密码就可以进入了
自动回送服务器,然后对应dropdownlist2的选项改变。
2个DropDownList第一个取出来,再加个隐藏域,保存第一个DropDownList取出来的值,第2个DropDownList的数据源参数从这个隐藏域取值
首先dropdownlist1 属性要设置为AutoPostBack为true
Page_Load里
if(!ispostback)
dropdownlist1 绑定数据库,可以设置显示默认计算机软件类.
dropdownlist2 绑定数据库,设置显示默认计算机软件类下的各项
DataTextField="计算机软件类";//显示在页面的值;
DataValueField="ID";//实际的值; 在dropdownlist1 的选择项改变时,触发DropDownList1_SelectedIndexChanged,主要代码如下:
根据string text=DropDownList1.SelectedValue的值,在数据库中匹配,重新绑定dropdownlist2
刷新就设dropdownlist1的属性 AutoPostBack="true"然后在dropdownlist1的OnSelectedIndexChanged="dropdownlist1_SelectedIndexChanged"事件里根据dropdownlist1.SelectValue查询数据绑定dropdownlist2
无刷新从网上搜吧,有很多
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Calendar1.Style["position"] = "absolute";
this.TextBox1.DataBind();
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList2.Items.Clear();
switch (this.DropDownList1.SelectedValue)
{
case "北京":
this.DropDownList2.Items.Add("天安门广场");
this.DropDownList2.Items.Add("颐和园");
this.DropDownList2.Items.Add("雍和宫");
this.DropDownList2.Items.Add("红螺寺");
break;
case "上海":
this.DropDownList2.Items.Add("崇明岛");
this.DropDownList2.Items.Add("外滩");
this.DropDownList2.Items.Add("万佛阁");
break;
case "香港":
this.DropDownList2.Items.Add("海洋公园");
this.DropDownList2.Items.Add("半岛酒店");
break;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
ShowResult();
} protected void Button1_Click(object sender, EventArgs e)
{
try
{
this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text);
}
catch
{
}
this.Calendar1.Visible = true;
} protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString();
this.Calendar1.Visible = false;
ShowResult();
} void ShowResult()
{
this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue;
UpdatePanel3.Update();
}
</script><!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>在开发ajax应用初期使用基本的asp.net ajax功能,避免那种奢谈一大堆javascript的做法</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>香港</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
请输入日期:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="147px" Text="<%# DateTime.Now.AddDays(20).ToShortDateString() %>" />
<asp:Button ID="Button1" runat="server" Text="..." OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"
BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True"
Width="220px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<hr />
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
result:
<asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Size="Small"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>