将asp转发器与转发器外的对象连接起来

时间:2014-03-28 09:42:23

标签: c# asp.net repeater

我的转发器中有一个下拉列表..我想将其值复制到转发器外的文本框..

这是我想做的事情

dropdown[1] to textbox1复制值 从dropdown[2] to textbox2复制值,依此类推......

这是我的代码

ASP:
    <asp:DropDownList ID="fmFrom" runat="server" Height="20px" Width="120px" DataSourceID="BrDatasource" DataTextField="branchName" DataValueField="branchCode" AutoPostBack="true" onselectedindexchanged="fmFrom_SelectedIndexChanged"></asp:DropDownList>

C#:

protected void fmFrom_SelectedIndexChanged(object sender, EventArgs e)
{
  for (int i = 0; i < rateRepeater.Items.Count; i++)
    {
        DropDownList from = (DropDownList)rateRepeater.Items[i].FindControl("fmFrom");
        TextBox1.Text = from.SelectedValue.ToString();
    }
}

此处我的所有文本框仅获取最后一个下拉列表的值...
我该怎么办?

2 个答案:

答案 0 :(得分:1)

尝试:

protected void fmFrom_SelectedIndexChanged(object sender, EventArgs e)
{
    for (int i = 0; i < rateRepeater.Items.Count; i++)
    {
        DropDownList from = (DropDownList)rateRepeater.Items[i].FindControl("fmFrom");
        ((TextBox)FindControl("TextBox" + (i + 1))).Text = from.SelectedValue.ToString();
    }
}

答案 1 :(得分:0)

改变这个:

TextBox1.Text = from.SelectedValue.ToString();

为:

TextBox1.Text += from.SelectedValue.ToString();