求救asp.net (c#) 在GridView中放置 RadioButtonList后问题
答案:2 悬赏:10
解决时间 2021-11-07 02:06
- 提问者网友:寂寞撕碎了回忆
- 2021-11-06 11:12
求救asp.net (c#) 在GridView中放置 RadioButtonList后问题
最佳答案
- 二级知识专家网友:轻雾山林
- 2021-11-06 12:35
在Gridview绑定数据即OnRowDataBound时添加事件,方法为"GridView1_RowDataBound"
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
RadioButtonList rbl = (RadioButtonList )e.Row.FindControl("RadioButtonList 控件名称");
if (rbl != null)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
///...........在此中间请进行RadioButtonList原有数据的绑定,否则会报错。
rbl .Text = drv["要绑定的字段对应RadioButtonList 中的选中值"].ToString();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
RadioButtonList rbl = (RadioButtonList )e.Row.FindControl("RadioButtonList 控件名称");
if (rbl != null)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
///...........在此中间请进行RadioButtonList原有数据的绑定,否则会报错。
rbl .Text = drv["要绑定的字段对应RadioButtonList 中的选中值"].ToString();
}
}
全部回答
- 1楼网友:胯下狙击手
- 2021-11-06 13:38
在错误这行前面加上是否为空的判断
if(rb.Selecteditem!=null)
result=Convert .ToInt32 (rb.SelectedItem .Value );
if(rb.Selecteditem!=null)
result=Convert .ToInt32 (rb.SelectedItem .Value );
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯