UpdatePanel中DropDownList无反应,该怎么处理
UpdatePanel中DropDownList无反应
前台代码
后台代码
前台代码
<%@ 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());
}
}
}