用什么方法获取GRIDVIEW模板里RadioButtonList的选中值啊?

来源:百度知道 编辑:UC知道 时间:2024/06/18 18:16:35
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = this.GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
string aa = ((RadioButtonList)gvr.Cells[15].FindControl("RadioButtonList1")).SelectedItem.Text;
}
这样就会出现未将对象引用到对象的实例!
我如果用string TelState = (gvr.FindControl("RadioButtonList1") as RadioButtonList).SelectedIndex.ToString();就会显示-1,就说明什么也没选!
怎么回事啊?
控件是放在模板里的
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="242px">
<asp:ListItem Value="0">通知已成功</asp:ListItem>
<asp:ListItem Value="1">通知成功,但还有其他事项</asp:ListItem>
<asp:ListItem Value="2">没通知成功</asp:ListItem>

ddl=(DropDowmList)gvr.FindControl("RadioButtonList1");
string s=ddl.selectedItem.text.Tostring();
你试试看,我也不保证对.

和我昨天一样

前台
<asp:TemplateField HeaderText="姓名">
<EditItemTemplate>
<asp:TextBox ID="txtstuName" runat="server" Text='<%# Bind("stuName") %>'
Width="100px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("stuName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>

后台代码
stu.stuName = ((TextBox)GridView1.Rows[e.