?? 為模板列中的單選按鈕添加事件.txt
字號:
為模板列中的單選按鈕定閱事件
1.默認不能全是選中,否則,事件不觸發
2.單選為動態創建,所以必須在代碼中增加事件.
<asp:RadioButton id=rbItem runat="server" >
private void DataGridEx1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RadioButton cbIsDefault = (RadioButton)e.Item.Cells[4].FindControl("rbItem");//是否是缺省
if(cbIsDefault!=null)
{
cbIsDefault.AutoPostBack=true;
cbIsDefault.CheckedChanged+=new EventHandler(cbIsDefault_CheckedChanged);
}
}
}
private void cbIsDefault_CheckedChanged(object sender, EventArgs e)
{
if(!(sender is RadioButton)) return;
for(int i=0; i<DataGridEx1.Items.Count; i++)
{
RadioButton rbtn = (RadioButton)DataGridEx1.Items[i].FindControl("rbItem");
rbtn.Checked = false;
}
((RadioButton)sender).Checked=true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -