0
我有3個RadionButtonList有線連接到相同的SelectedIndexChanged事件,故意。有沒有辦法確定哪個RadioButtonList只有一個項目點擊編程?SelectedIndexChanged多個RadionButtonList
我有3個RadionButtonList有線連接到相同的SelectedIndexChanged事件,故意。有沒有辦法確定哪個RadioButtonList只有一個項目點擊編程?SelectedIndexChanged多個RadionButtonList
您可以使用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
}
}
好的,這是一個好主意。謝謝! – dawsoad
在屬性 - >事件 –