//这个是一个按钮控件的click事件代码
protected void BtnSumit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in Gridview1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
string Grade = ((RadioButtonList)row.FindControl("RadList1")).SelectedValue; }
}
}在我的gridview中自定义了radioButtonList控件:
<ItemTemplate>
<asp:RadioButtonList ID="RadList1" runat="server"
RepeatDirection="Horizontal" AppendDataBoundItems="True">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
出现的问题:在网页Gridview1中点击RadioButtonList控件,然后点击提交按钮,响应按钮事件时,使用FindControl是可以找得到RadioButtonList控件的,但是string Grade = ((RadioButtonList)row.FindControl("RadList1")).SelectedValue;
这句代码Grade的值却为空。求各路大侠指点!!!!!!
protected void BtnSumit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in Gridview1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
string Grade = ((RadioButtonList)row.FindControl("RadList1")).SelectedValue; }
}
}在我的gridview中自定义了radioButtonList控件:
<ItemTemplate>
<asp:RadioButtonList ID="RadList1" runat="server"
RepeatDirection="Horizontal" AppendDataBoundItems="True">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
出现的问题:在网页Gridview1中点击RadioButtonList控件,然后点击提交按钮,响应按钮事件时,使用FindControl是可以找得到RadioButtonList控件的,但是string Grade = ((RadioButtonList)row.FindControl("RadList1")).SelectedValue;
这句代码Grade的值却为空。求各路大侠指点!!!!!!
解决方案 »
- 把DataTable放到Cache后再清除这个DataTable,为什么使用Cache时行数据丢失?
- 求GridView导出到excel,javascript源码?
- C++程序转一下C#
- 如何合并两个DataTable对象?
- 怎样判断页面是否被刷新
- .NET 如何:从A域名指向到B网站时,地址栏仍显示A域名.
- 蛙蛙推荐:微软网络讲座系列教程视频下载(2004年1月到2005年4越)
- 不懂:在<td></td>中用datalist怎么会出这么怪事啊?(up有分)
- 有知道如何使用aspose excel组件的吗?
- 如何根据sessionid从SQLServer中取得session?
- 如何将html页面转换为word文档
- 请教一个从html代码中获取需要内容的问题
写了个 你改成这样看看protected void BtnSumit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in Gridview1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rbs = ((RadioButtonList)row.FindControl("RadList1"));
for (int i = 0; i < rbs.Items.Count; i++)
{
if (rbs.Items[i].Selected == true)
{
Response.Write(rbs.Items[i].Text)//or Value
}
}
}
}
}
{
string selectValue = string.Empty;
foreach (GridViewRow item in this.gvList.Rows)
{
RadioButtonList rList = (RadioButtonList)item.FindControl("RadList1");
if (rList.SelectedValue != string.Empty)
{
selectValue += rList.SelectedValue + ";";
}
}
//输出每个RadioButtonList选择的值
Response.Write(selectValue);
}
{
foreach (GridViewRow row in this.GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
RadioButtonList button = ((RadioButtonList)row.FindControl("RadioButtonList"));
ListItem item = button.SelectedItem;
string value = item.Value;
Response.Write("<script>alert('" + value + "');</script>");
}
}
}