页面代码如下:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    AllowPaging="True" PageSize="1" DataSourceID="SqlDataSource1" onpageindexchanged="GridView1_PageIndexChanged">
        <Columns>
             <asp:TemplateField>
                  <ItemTemplate>
                       <table style="width: 100%; height: 358px">
                           <tr>
                              <td colspan="2">
                                 <asp:Label ID="Label11" runat="server" Text="作答:"></asp:Label>
                                 <asp:RadioButton ID="RadioButton1" runat="server" ForeColor="Red" 
                                            GroupName="as" Text="A" />
                                 <asp:RadioButton ID="RadioButton2" runat="server" ForeColor="Red" 
                                            GroupName="as" Text="B" />
                                 <asp:RadioButton ID="RadioButton3" runat="server" ForeColor="Red" 
                                            GroupName="as" Text="C" />
                                 <asp:RadioButton ID="RadioButton4" runat="server" ForeColor="Red" 
                                            GroupName="as" Text="D" />
                              </td>
                            </tr>
                       </table>
                   </ItemTemplate>
            </asp:TemplateField>
         </Columns>
</asp:GridView>  我想获取GridView中ItemTemplate中table中用户选了哪个RadioButton。我在cs文件中如何获取?

解决方案 »

  1.   

    RadioButton RB= e.Row.findControl("RadioButton") as RadioButton;
      

  2.   

    看我的代码:onpageindexchanged="GridView1_PageIndexChanged" 这个事件。当页码变化以后才获取这个值。
    这个事件的EventArgs参数根本没有Row这个属性。
      

  3.   

    楼主,你不要用GridView的PageIndexChanged事件,你换成PageIndexChanging事件,然后再用一楼的代码两个事件参数的不同:
    1、PageIndexChanged
            protected void GridView1_PageIndexChanged(object sender, EventArgs e)
            {        }
    2、PageIndexChanging
            protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {        }
      

  4.   

    你想在那个事件获取呢?
    gridview外面就foreach (GridViewRow gr in GridView1.Rows)
            {            RadioButton chk = (RadioButton)gr.Cells[列数].FindControl("RadioButton1");
                if (chk.Checked)
                {                          }
            }
      

  5.   

    PageIndexChanging 索引改变时触发
    PageIndexChanged 改变之后才触发
      

  6.   

    foreach (GridViewRow gvr in GridView1.Rows)
      {
        RadioButton rb= ((RadioButtonList)gvr.FindControl("RadioButton1"));}