永发信息网

求救asp.net (c#) 在GridView中放置 RadioButtonList后问题

答案:2  悬赏:60  手机版
解决时间 2021-03-17 13:41
  • 提问者网友:你给我的爱
  • 2021-03-16 20:18
求救asp.net (c#) 在GridView中放置 RadioButtonList后问题
最佳答案
  • 五星知识达人网友:旧脸谱
  • 2021-03-16 20:24
在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();
}
}
全部回答
  • 1楼网友:一秋
  • 2021-03-16 20:51
在错误这行前面加上是否为空的判断
if(rb.Selecteditem!=null)
result=Convert .ToInt32 (rb.SelectedItem .Value );
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯