protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int id =Convert.ToInt32( this.DropDownList1.SelectedValue); DataSet dt = new DataSet(); string sql="select * from A where id="+id; //id为子类的父类ID SqlConnection con="这里写数据库连接字符串"; SqlDataAdapter sta = new SqlDataAdapter(con, sql); sta.Fill(dt); this.DropDownList2.DataSource = dt; this.DropDownList2.DataBind(); }
前台代码:
<asp:DropDownList ID="province" runat="server" AutoPostBack="True" > </asp:DropDownList>
后台代码:
一个button 按钮 protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.Text = this.province.DataTextField.ToString();
this.TextBox1.Text = this.province.DataValueField.ToString();
this.TextBox1.Text = this.province.SelectedValue.ToString();
this.TextBox1.Text = this.province.Text.ToString();
}
这几种方式 ,数据都没有显示 ,请问怎么获取当前dropdownlist中的值,赋给 textbox呢 ?
试试
祝你好运
设置dropdownlist的viewstate为true试试。。
这里有很多啊。
{
int id =Convert.ToInt32( this.DropDownList1.SelectedValue);
DataSet dt = new DataSet();
string sql="select * from A where id="+id; //id为子类的父类ID
SqlConnection con="这里写数据库连接字符串";
SqlDataAdapter sta = new SqlDataAdapter(con, sql);
sta.Fill(dt);
this.DropDownList2.DataSource = dt;
this.DropDownList2.DataBind();
}
http://blog.csdn.net/sandyxxx/archive/2008/04/28/2337281.aspx
<asp:DropDownList ID="province" runat="server" AutoPostBack="True" > </asp:DropDownList>
后台代码:
一个button 按钮 protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.Text = this.province.DataTextField.ToString();
this.TextBox1.Text = this.province.DataValueField.ToString();
this.TextBox1.Text = this.province.SelectedValue.ToString();
this.TextBox1.Text = this.province.Text.ToString(); }
这几种方式 ,数据都没有显示 ,请问怎么获取当前dropdownlist中的值,赋给 textbox呢 ?