我在这个转发器里面有一个转发器和一个下拉列表

时间:2013-04-24 12:25:30

标签: asp.net drop-down-menu repeater sender itemdatabound

我在转发器中填充dropdownlist(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");
    }

1 个答案:

答案 0 :(得分:0)

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

尝试将Repeater.DataBind()来电转移到OnInit()事件。