关于gridview里使用radiobutton
来源:互联网 发布:南宁java培训 编辑:程序博客网 时间:2024/06/03 20:36
<body>
<script language="javascript" type="text/javascript">
<script type="text/javascript">
function setRadio(nowRadio)
{
var myForm,objRadio;
myForm=document.forms[0];
///alert(myForm);
for(var i=0;i<myForm.length;i++)
{
if(myForm.elements[i].type=="radio")
{
objRadio=myForm.elements[i];
///alert(objRadio.name);
if(objRadio!=nowRadio && objRadio.name.indexOf("GridView1")>-1 && objRadio.name.indexOf("RadioButton1")>-1)
{
alert(objRadio.name);
if(objRadio.checked)
{
objRadio.checked=false;
}
}
}
}
}
</script>
</script>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="试例1" DataField="test1" />
<asp:BoundField HeaderText="试例2" DataField="test2" />
<asp:BoundField HeaderText="试例3" DataField="test3" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
InitGrid();
}
}
public void InitGrid()
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("test1", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("test2", typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("test3", typeof(string));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["test1"] = "111";
dr["test2"] = "222";
dr["test3"] = "333";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["test1"] = "444";
dr["test2"] = "555";
dr["test3"] = "666";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["test1"] = "777";
dr["test2"] = "888";
dr["test3"] = "999";
dt.Rows.Add(dr);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton rdb = (RadioButton)e.Row.Cells[0].FindControl("RadioButton1");
rdb.Attributes.Add("onclick", "setRadio(this)");
}
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
//我不知道你所说的选中是什么意思,如果仅仅是GridView的SelectedIndex改变,以下代码就够了
RadioButton rdb = sender as RadioButton;
int index = (rdb.NamingContainer as GridViewRow).RowIndex;
this.GridView1.SelectedIndex = index;
InitGrid();
}
gridview中radiobutton的使用就是上边这些代码,
- 关于gridview里使用radiobutton
- 在GridView里使用单选按钮,RadioButton/Radio
- 在GridView里使用单选按钮,RadioButton/Radio
- 在GridView里使用单选按钮,RadioButton/Radio
- gridview 中RadioButton 使用
- 在GridView里使用CheckBox
- 在GridView里使用CheckBox
- 在GridView里使用CheckBox
- GridView里Ckeckbox的使用
- Android 使用GridView来实现类似RadioButton的多行单选功能
- Android 使用GridView来实现类似RadioButton的多行单选功能
- gridview radiobutton/radio
- GridView RadioButton 样板列
- 关于RadioButton的定义及使用举例
- 关于GridView的使用,
- jquery处理关于Gridview中的RadioButton不能实现单选的功能的解决方案
- 在gridview中放radiobutton
- GridView中RadioButton单选
- 医学词汇
- 数据库的简单优化
- DB排他的处理方法
- jQuery的表单验证插件
- VHDL数据类型转换
- 关于gridview里使用radiobutton
- 转载别人的文章:经典管理学定律
- struts生成登录验证码
- 单例模式
- 非常漂亮窗体界面控件
- 坚持学习WF(2):WF创作模式和设计时工具
- dll網站
- 在IIS上启用Gzip压缩(HTTP压缩)
- 项目中用到的全文搜索(lucene与Compass)