多个 RadionButtonList 的 SelectedIndexChanged
SelectedIndexChanged for multiple RadionButtonList
我有 3 个 RadionButtonList 有意连接到同一个 SelectedIndexChanged 事件。有没有办法确定哪个 RadioButtonList 刚刚以编程方式单击了其中一个项目?
您可以使用 RadioButtonList 对象的 ID
属性来执行此操作,只要在触发事件时获取 sender
对象的 ID。
protected void RadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
string listName = ((RadioButtonList)sender).ID
// listName = RadioButtonList1 or RadioButtonList2 or whatever the ID is set to.
if (listName == "RadioButtonList1")
{
// Rest of your code goes here, now that you know which RadioButtonList the event was fired from
}
}
我有 3 个 RadionButtonList 有意连接到同一个 SelectedIndexChanged 事件。有没有办法确定哪个 RadioButtonList 刚刚以编程方式单击了其中一个项目?
您可以使用 RadioButtonList 对象的 ID
属性来执行此操作,只要在触发事件时获取 sender
对象的 ID。
protected void RadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
string listName = ((RadioButtonList)sender).ID
// listName = RadioButtonList1 or RadioButtonList2 or whatever the ID is set to.
if (listName == "RadioButtonList1")
{
// Rest of your code goes here, now that you know which RadioButtonList the event was fired from
}
}