UpdatePanel中DropDownList无反应
前台代码
后台代码
点击cbDep是不触发cbDep_SelectedIndexChanged事件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestDroplist.aspx.cs" Inherits="TestDroplist" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID ="cbDep" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="cbDep" runat="server" AutoPostBack ="true"
onselectedindexchanged="cbDep_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="cbMaj" runat="server" AutoPostBack ="true">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class TestDroplist : System.Web.UI.Page
{
DataTable GetDataTable(string sql)
{
DataTable dt = null;
try
{
SqlConnection Conn = new SqlConnection("Data Source=127.0.0.1;database=olpv;uid=sa;pwd=hxyw801102");
Conn.Open();
SqlCommand Cmd = new SqlCommand(sql, Conn);
dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(Cmd);
da.Fill(dt);
Conn.Close();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.StackTrace + "')</script>");
}
return dt;
}
void FillDropList(DropDownList obj, string sql)
{
obj.Items.Clear();
obj.Items.Add("");
DataTable dt = GetDataTable(sql);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
obj.Items.Add(row[0].ToString());
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropList(cbDep, "select DepartmentName from Info_Department");
}
}
protected void cbDep_SelectedIndexChanged(object sender, EventArgs e)
{
FillDropList(cbMaj, "select Info_Major.Major from Info_Department,Info_Major where Info_Department.DepartmentID=Info_Major.DepartmentID and Info_Department.DepartmentName='" + cbDep.Text + "'");
}
}
点击cbDep是不触发cbDep_SelectedIndexChanged事件
...全文
相关推荐
asp.net Dropdownlist结合CheckBoxList多选下拉框
asp.net Dropdownlist结合CheckBoxList多选下拉框
asp.net中dropdownlist使用AJAX联动
asp.net中dropdownlist使用AJAX联动
DropDownList设置客户端事件思路
假设:数据源控件GrdiView,无刷新UpdatePannel,友情提示UpdateProgress,分页下拉框DropDownList 一般情况下:Gridview的分页有linkbutton或者button,这样要是想让UpdateProgress提示,很简单,先让GridView隐藏,然后给它加个OnClientClick就搞定! 在DropDownList的onchange事件里: function selectChange() { if ($(select option).is(:selected)) { $(#btn11).click(
c#语言Asp.net与DropDownList无刷新数据绑定
用vs2005开发工具。c#语言Asp.net与DropDownList无刷新数据绑定。
AJAX实现dropdownlist无刷新动态绑定,联动
AJAX做的dropdownlist无刷新动态绑定



