Asp.net中使用GridView的单选按钮
2013-05-22 15:08
375 查看
1、为GridView添加新列,选择字段类型为TemplateField,页眉文本为“选择” 2、编辑模版,为其添加RadioButton,并将其属性设为自动回发。 3、获取GridView中的某个单选按钮 RadioButton rb = (RadioButton)ImageView.Rows[0].Cells[0].FindControl("RadioButton1" ); rb.Checked = true; ImageView.SelectedIndex = 0; 4、为GridView添加RowDataBound事件 添加该事件的处理方法: if (e.Row.RowType == DataControlRowType .DataRow) { RadioButton rdb = (RadioButton)e.Row.Cells[0].FindControl("RadioButton1" ); rdb.Attributes.Add( "onclick", "setRadio(this)" );//为每一个单选按钮的单击事件 } 在前端界面添加setRadio的定义,把当前选择的按钮的checked设为true,其他设为false //处理单选按钮 function setRadio(nowRadio) { var myForm, objRadio; nowRadio.checked = true; myForm = document.forms[0]; for ( var i = 0; i < myForm.length; i++) { if (myForm.elements[i].type == "radio") { objRadio = myForm.elements[i]; if (objRadio != nowRadio) { if (objRadio.checked) objRadio.checked = false; } } } } 4、为单选按钮添加change事件 RadioButton rdb = sender as RadioButton ; int index = (rdb.NamingContainer as GridViewRow).RowIndex; this.ImageView.SelectedIndex = index;
相关文章推荐
- asp.net GridView中使用RadioButton单选按钮的方法
- ASP.NET中 RadioButton(单选按钮)的使用
- asp.net 扩展GridView 增加单选按钮列的代码
- ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
- ASP.NET中 RadioButtonList(单选按钮组)的使用
- Asp.net 中使用GridView控件实现Checkbox单选
- ASP.NET中 RadioButton(单选按钮)的使用
- ASP.NET中 RadioButtonList(单选按钮组),CheckBoxList(复选框组),DropDownList(下拉框),ListBox(列表框),BulletedList(无序列表)的使用前台绑定
- ASP.NET中 RadioButtonList(单选按钮组)的使用
- asp.net MVC 单选按钮的使用
- ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
- 遇到的问题------Asp.net使用GridView的编辑修改功能回发无效
- ASP.NET Gridview 中使用checkbox删除的2种方法实例分享
- 使用ASP.NET 2.0 GridView轻松操作数据
- asp.ent gridview 自定义按钮使用
- ASP.NET动态生成GridView的使用
- 在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据
- 在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据(2)