0

我在中继器内填充下拉列表(DropDownList 填充了数据库中的值)

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string idAdvert = objAdvert.GetAllIlanPage(ClsSession.idUser, null).Rows[i]["ID_ADVERT"].ToString();
                DropDownList DDL = (DropDownList)e.Item.FindControl("DropDownList1");
                DDL.Items.Add("");
                DDL.Items.Add(new ListItem("Doping", idAdvert));
                DDL.Items.Add(new ListItem("İşlem", idAdvert));
                DDL.SelectedIndex = 0;
                i = i + 1;

            }
        }

它正在工作,但是当我单击下拉列表时,selectedindexchanged 不起作用。它总是发送 selectedIndex=1

 protected void SelectedIndex_Degisti(object sender, EventArgs e)
    {
        //DropDownList ddl = sender as DropDownList;
        //DropDownList doldurulacak_ddl = (DropDownList)ddl.Parent.FindControl("DropDownList1"); 
        ////Aynı satırdaki doldurulacak diğer droplisti bulduk.

        Control parent = ((Control)sender).Parent;
        DropDownList GeneralDDL = (DropDownList)parent.FindControl("DropDownList1");

        if (GeneralDDL.SelectedItem.Text == "Doping") ;//Response.Redirect("default.aspx");
        else if (GeneralDDL.SelectedItem.Text == "İşlem") ;// Response.Redirect("login.aspx");
    }
4

1 回答 1

0

由于您正在动态地将控件添加到 Repeater,因此您必须确保在每个 PostBack上重新添加这些控件。这将使 from 值能够设置为用户选择的值。

尝试将您的Repeater.DataBind()呼叫转移到OnInit()活动。

于 2013-04-24T17:14:56.143 回答