在gridview中添加了一个radiobuttonlist,如下:
<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
请各位指教
<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
请各位指教
{
RadioButtonList x = sender as RadioButtonList;
Label aslbl = x.NamingContainer.FindControl("aslbl") as Label;
aslbl.Visible = true;
aslbl.Text = x.SelectedValue;
}
要么你采用js去实现
谢谢
<%@ Page Language="C#" %><!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)
{
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 showxzgw1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList x = e.Row.FindControl("rbb") as RadioButtonList;
Label aslbl = e.Row.FindControl("aslbl") as Label;
for (int i = 0; i < x.Items.Count; i++)
{
x.Items[i].Attributes.Add("onclick", "document.getElementById('" + aslbl .ClientID+ "').innerHTML = this.value");
}
}
}
</script>
<body>
<form id="form1" runat="server">
<asp:GridView ID="showxzgw1" runat="server" AutoGenerateColumns="False"
GridLines="None" onrowdatabound="showxzgw1_RowDataBound">
<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">
<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"></asp:Label>
</li>
</ol>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>