日期:2014-05-17  浏览次数:20492 次

获取gridview中radiobuttonlist的值
在gridview中添加了一个radiobuttonlist,如下:
C# code
 <asp:GridView ID="showxzgw1" runat="server" AutoGenerateColumns="False" 
            GridLines="None"   >
        <Columns>
        <asp:TemplateField >
     <ItemTemplate>
            <asp:Label ID="xzidlbl" runat="server" Text='<%# Eval("id") %>' Visible="false"></asp:Label>
        <ol start="1">
        <li>
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("timu") %>'></asp:Label>
                            <asp:RadioButtonList ID="rbb" runat="server" 
                                RepeatDirection="Vertical" RepeatLayout="Table" 
                              AutoPostBack="False" onselectedindexchanged="rbb_SelectedIndexChanged">
                                <asp:ListItem Text="A" Value="A">A</asp:ListItem>
                                <asp:ListItem Text="B" Value="B">B</asp:ListItem>
                                <asp:ListItem Text="C" Value="C">C</asp:ListItem>
                                <asp:ListItem Text="D" Value="D">D</asp:ListItem>
                            </asp:RadioButtonList>
                                     
                    <asp:Label ID="aslbl" runat="server" Visible="False"></asp:Label>
                          
            </li>
        </ol>
     </ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>

 想在选择一项后,能把所选项的text 如A,B,C,D,通过aslbl显示出来,不知道怎么做呢
如果直接从gridview中取值,radiobuttonlist的selectindex显示为-1
请各位指教

------解决方案--------------------
你怎么测试的不行啊????

你直接拷贝粘贴下面的代码看效果
HTML code
<%@ Page Language="C#" EnableViewState="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
  {
    DateTime x = DateTime.ParseExact("22/06/2011", "dd/MM/yyyy", null);
    Response.Write(x.ToString());
    System.Data.DataTable dt = new System.Data.DataTable();
    if (!Page.IsPostBack)
    {
      System.Data.DataRow dr;
      dt.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32)));
      dt.Columns.Add(new System.Data.DataColumn("timu", typeof(System.String)));
      for (int i = 0; i < 6; i++)
      {
        dr = dt.NewRow();
        dr[0] = i;
        dr[1] = "【孟子E章】" + i.ToString();
        dt.Rows.Add(dr);
      }
      showxzgw1.DataSource = dt;
      showxzgw1.DataBind();
    }
  }

  protected void rbb_SelectedIndexChanged(object sender, EventArgs e)
  {
    RadioButtonList x = sender as RadioButtonList;
    Label aslbl = x.NamingContainer.FindControl("aslbl") as Label;
    aslbl.Visible = true;
    aslbl.Text = x.SelectedValue;
  }
</script>
<body>
  <form id="form1" runat="server">
  <asp:GridView ID="showxzgw1" runat="server" AutoGenerateColumns="False" GridLines="None">
    <Columns>
      <asp:TemplateField>
        <ItemTemplate>
          <asp:Label ID="xzidlbl" runat="server" Text='<%# Eval("id") %>' Visible="false">&l