Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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# 如何在dropdown selected index change事件中查找中继器内的dropdown selected值?_C#_Asp.net - Fatal编程技术网

C# 如何在dropdown selected index change事件中查找中继器内的dropdown selected值?

C# 如何在dropdown selected index change事件中查找中继器内的dropdown selected值?,c#,asp.net,C#,Asp.net,您只需将事件处理程序中的sender参数强制转换为DropDownList。它总是事件的源头。因此无需使用FindControl: protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { //DropDownList DropDownList1 = (DropDownList)sender; //string SelectedValue = DropDownList1.Sel

您只需将事件处理程序中的
sender
参数强制转换为
DropDownList
。它总是事件的源头。因此无需使用
FindControl

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //DropDownList DropDownList1 = (DropDownList)sender;
    //string SelectedValue = DropDownList1.SelectedValue;
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DropDownList ddldrop = (DropDownList)e.Item.FindControl("DropDownList1");
        int  value =Convert.ToInt32( ddldrop.SelectedValue);
        Supervisor sup = new Supervisor();
    if (value ==1 ) {
            sup.Status = "Accept";
            sup.Save();
        }
    }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    //Supervisor sup = new Supervisor();
    //sup.Status = "Accept";
    //sup.Save();
}

在上一篇文章中已经为您提供了解决方案。请参考并试一试
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //DropDownList DropDownList1 = (DropDownList)sender;
    //string SelectedValue = DropDownList1.SelectedValue;
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DropDownList ddldrop = (DropDownList)e.Item.FindControl("DropDownList1");
        int  value =Convert.ToInt32( ddldrop.SelectedValue);
        Supervisor sup = new Supervisor();
    if (value ==1 ) {
            sup.Status = "Accept";
            sup.Save();
        }
    }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    //Supervisor sup = new Supervisor();
    //sup.Status = "Accept";
    //sup.Save();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
   DropDownList ddl = (DropDownList) sender;
   string selectedValue = ddl.SelectedValue;
   // ...
}