DropDownList_Changed事件,textbox.Text获取ddl的值

解决方案 »

  1.   

    你循环遍历一下模板列里的DropDownList ,看看哪个的Selected是改变的
    然后就把改变的那个DropDownList的值赋于对应的TextBox不就行了。。
     
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow grRow in this.GridView1.Rows)
            {
                DropDownList dr = (DropDownList)grRow.Cells[0].FindControl("DropDownList1");
                if (dr != null)
                {
                    if (dr.SelectedIndex != 0)
                    {
                        TextBox tb = (TextBox)grRow.Cells[1].FindControl("TextBox1");
                        if (tb != null)
                        {
                            tb.Text = dr.SelectedItem.Text.ToString();
                        }
                    }
                }
            }
        }
      

  2.   


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
        (TextBox)(DropDownList(sender)).Parent.Parent.FindControl("TextBox1").Text=e.SelectedItem.Text.ToString();
    //这样就应该可以,没有问题.第一个parent 代表的是包含你选择的dropdownlist的cell,在parent表示的是cell所在的row 然后执行findcontrol既可以了 ;没有必要向五楼那样循环 
        }
    以上的代码有可能不准确,你只要使用这个思想就可以了
      

  3.   

     
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {TextBox t = (TextBox)((DropDownList)sender).Parent.Parent.FindControl("TextBox1");
            if (t != null)
            {
                t.Text = ((DropDownList)sender).SelectedValue.ToString();
            }
    }