Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法捕获中继器内文本框中的下拉选择值_C#_Asp.net - Fatal编程技术网

C# 无法捕获中继器内文本框中的下拉选择值

C# 无法捕获中继器内文本框中的下拉选择值,c#,asp.net,C#,Asp.net,我在中继器中有一个DropDownList,每当所选文本被更改时,我都必须在TextBox中显示它,但我得到的对象引用未设置为对象的实例错误 protected void Ddl_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList) sender; RepeaterItem item = (RepeaterItem) ddl .NamingContaine

我在中继器中有一个
DropDownList
,每当所选文本被更改时,我都必须在
TextBox
中显示它,但我得到的
对象引用未设置为对象的实例
错误

protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl   = (DropDownList)  sender;
    RepeaterItem item  = (RepeaterItem)  ddl .NamingContainer;
    TextBox txt        = (TextBox) item.FindControl("TextBox4");
    txt.Text           = ddl.SelectedItem.Text;
}

只需将Ddl dropdowns autopost back属性启用为true,并添加以下代码行:

protected virtual void RepeaterItemCreated(object sender, RepeaterItemEventArgs e)
{
    DropDownList MyList = (DropDownList)e.Item.FindControl("ddl");
    MyList.SelectedIndexChanged += ddl_SelectedIndexChanged;
}

protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
 {
     RepeaterItem item  = (RepeaterItem)  Page.FindControl("repeatorid");
     TextBox txt        = (TextBox) item.FindControl("TextBox4");
     txt.Text           = ddl.SelectedItem.Text;     
 }

哪条线路出故障了?TextBox也在中继器内吗?最后一行txt.Text=ddl.SelectedItem.Text;是,文本框在repeater@Newbie你确定定义了
txt
了吗?你所说的txt是什么意思?好的,检查下面的链接我的文本框在页脚模板中。