第一个dropdownlist1选择不同的数据触发SelectedIndexChanged事件读取数据后,使第二个dropdownlist2帮定根据这些数据又重数据库查询得到的数据.
注:dropdownlist的autopostback已经设为true
这个例子的代码请高手写个?谢谢
注:dropdownlist的autopostback已经设为true
这个例子的代码请高手写个?谢谢
解决方案 »
- 为什么用jQuery的even之后会是这样的结果,给个理由!!!
- 正则表达式
- 项目打不开了 引用的类库报错 怎么办啊 急啊
- IE9下使用coolite或Ext.net的问题,报js错
- TabContainer问题(ToolsKit3.5的)
- 100′求一个button特效 等ing……
- 关于文章发布系统的问题
- 有没有办法把SQLSERVER2000数据库中的 “表结构跟数据” 一起都生成sql,在另一太电脑用查询分析器还原?
- 动态绑定值
- 50分求一sql语句,不是很难的,请各位大虾帮忙!
- 返回DataTable对象,怎么写?
- 我以前的购物车的物品选择栏目DataGrid是绑定数据库的,现在要用TreeView来做,应该怎样做呢?急
{
for(int i=0;i<5;i++)
{
DropDownList1.Items.Add(i.ToString());
}
DropDownList1.DataBind();
}
for(int i=1;i<5;i++)
{
DropDownList2.Items.Add(i.ToString());
}
DropDownList2.DataBind();
DropDownList2.SelectedValue = DropDownList1.SelectedValue;
{
if(!IsPostBack)
{
for(int i=0;i<5;i++)
{
DropDownList1.Items.Add(i.ToString());
}
DropDownList1.DataBind();
}
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
for(int i=1;i<5;i++)
{
DropDownList2.Items.Add(i.ToString());
}
DropDownList2.DataBind();
DropDownList2.SelectedValue = DropDownList1.SelectedValue;
}
{
if(!IsPostBack)
{
bindDrop();
}
}
private void bindDrop()
{
//绑定主频道
string str = "SELECT ID,CHANNEL_NAME FROM Channel_Manage WHERE (Parent_ID = 0)";
ddlistChannel.DataSource = xtDAO.SqlText.ExecuteDataset(str);
ddlistChannel.DataTextField = "Channel_Name";
ddlistChannel.DataValueField = "ID";
ddlistChannel.DataBind();
ddlistChannel.Items.Insert(0,"");
}private void BindChannelType()
{
string PARENT_ID = "-1";
if ( ddlistChannel.SelectedValue !="" )
PARENT_ID = ddlistChannel.SelectedValue;
//绑定子频道
string str = "SELECT ID,CHANNEL_NAME FROM Channel_Manage WHERE PARENT_ID = " + PARENT_ID;
ddlistChannelType.DataSource = xtDAO.SqlText.ExecuteDataset(str);
ddlistChannelType.DataTextField = "CHANNEL_NAME";
ddlistChannelType.DataValueField = "ID";
ddlistChannelType.DataBind();
}
private void ddlistChannel_SelectedIndexChanged(object sender, System.EventArgs e)
{
BindChannelType();
}
{
string strConn = "Server=(local);User id=sa;Pwd=20048692;Database=xingxi";
//string strCmd = "select leixing from [leixing]";
string strCmd1 = "select class1 from [class1]";
//string strCmd2 = "select class2 from [class2] where class1 like '%"+ DropDownList2.SelectedItem.ToString() +"%'";
string strCmd2 = "SELECT class2 FROM class2 WHERE (class1 LIKE '交易买卖')";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = strConn;
conn.Open();
SqlCommand cmd1 = new SqlCommand(strCmd1,conn);
myReader1 = cmd1.ExecuteReader(); DropDownList2.DataSource=myReader1;
DropDownList2.DataTextField = "class1";
DropDownList2.DataBind();
//DropDownList2.Items.Insert(0,"");
cmd1.Connection.Close();
cmd1.Connection.Open(); SqlCommand cmd2 = new SqlCommand(strCmd2,conn);
myReader2 = cmd2.ExecuteReader(); DropDownList3.DataSource=myReader2;
DropDownList3.DataTextField = "class2";
DropDownList3.DataBind();
cmd2.Connection.Close();
cmd2.Connection.Open();
conn.Close();
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList2.SelectedIndexChanged += new System.EventHandler(this.DropDownList2_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
tupian.Visible=true;
} private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strConn = "Server=(local);User id=sa;Pwd=20048692;Database=xingxi";
string strCmd4 = "select class2 from [class2] where class1 like '%"+ DropDownList2.SelectedValue +"%'";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = strConn;
conn.Open();
SqlCommand cmd3 = new SqlCommand(strCmd4,conn);
myReader3 = cmd3.ExecuteReader(); //数据绑定DropDownList控件
DropDownList3.DataSource=myReader3;
DropDownList3.DataTextField = "class2";
DropDownList3.DataBind();
cmd3.Connection.Close();
conn.Close();
这是我写的,你看看那个地方不对啊。
那么这句DropDownList2.SelectedItem.ToString() 将出错.
其它倒没看出哪里有错..