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;
// ...
}