문제

I have a dropdown in my repeater.. i want to copy its value to textbox that is outside repeaters..

here is what I want to do

copy value from dropdown[1] to textbox1
copy value from dropdown[2] to textbox2 and so on...

here is my code

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();
    }
}

here all my textbox gets the value of the last dropdown only...
what should I do?

도움이 되었습니까?

해결책

Try:

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();
    }
}

다른 팁

change this:

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

to:

TextBox1.Text += from.SelectedValue.ToString();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top