gridview模板列中为RadioButtonList 现在我再gridview的模版列中建立了一个radiobuttonlist,添加了 "很好","较好","可以","尚可","不好",几个项目,现在我想实现的是当我点很好的时候textbox框里面显示很好,当我点击较好的时候textbox框里显示较好,大家看清楚哦~是radiobuttonlist,不是radiobutton。请教如何取值~~~谢谢~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用for循环给radiobuttonlist每一项增加一个onclick事件test('很好'),把值传过去给textbox 用for循环给radiobuttonlist每一项增加一个onclick事件脚本test('很好'),把值传过去给textbox 模版列的radiobuttonlist改为Literal ID="litForRadio"GridView1_RowDataBound中:{Literal litForRadio = (Literal)e.Row.FindControl("litForRadio");TextBox txtForRadio = (TextBox)e.Row.FindControl("txtForRadio");string outhtml = @"<input type=radio name=gditem{0}radio onclick=""if(this.checked)document.getElementById('{1}').value='好';"" />好<br><input type=radio name=gditem{0}radio onclick=""if(this.checked)document.getElementById('{1}').value='不好';"" />不好<br>";//.....litForRadio.Text = string.Format(outhtml,e.Row.RowIndex,txtForRadio.ClientId);} <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function getRankValue(obj) { document.getElementById("<%=tb.ClientID %>").value=obj.value; } </script></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButtonList ID="rbtnRank" runat="server"> <asp:ListItem onclick="getRankValue(this)" Value="很好"></asp:ListItem> <asp:ListItem onclick="getRankValue(this)" Value="较好"></asp:ListItem> </asp:RadioButtonList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:TextBox ID="tb" runat="server"></asp:TextBox> </div> </form></body> 花了一个小时给你做了个demo,经过调试可满足你的要求:<%@ Page Language="C#" AutoEventWireup="true" Debug="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" datakeynames="ID" CommadName="Select" OnRowCreated="GridView1_RowCreated" > <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButtonList ID="SelectRadioButtonList1" runat="server" AutoPostBack="true" > <asp:ListItem Text="很好" Value="1" Selected="False" ></asp:ListItem> <asp:ListItem Text="较好" Value="2" Selected="False"></asp:ListItem> <asp:ListItem Text="尚可" Value="3" Selected="False"></asp:ListItem> <asp:ListItem Text="不好" Value="4" Selected="False"></asp:ListItem> </asp:RadioButtonList> </ItemTemplate> </asp:TemplateField> <asp:BoundField ShowHeader="true" DataField="ID" HeaderText="ID" /> <asp:BoundField ShowHeader="true" DataField="name" HeaderText="姓名" /> </Columns> </asp:GridView> <span>评价:</span> <asp:TextBox ID="SelectedRLText" runat="server" Text=""></asp:TextBox> </div> </form></body></html>using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page{ public class EntityTest { private int id; public int ID { get { return this.id; } set { this.id = value; } } private string name; public string Name { get { return this.name; } set { this.name = value; } } public EntityTest(int id, string name) { this.ID = id; this.Name = name; } } protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { this.GridView1.DataSource = CreateList(); this.GridView1.DataBind(); } } protected List<EntityTest> CreateList() { List<EntityTest> sourceList = new List<EntityTest> { new EntityTest(1, "aaa"), new EntityTest(2, "bbb"), new EntityTest(3, "ccc"), new EntityTest(4, "ddd") }; return sourceList; } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.FindControl("SelectRadioButtonList1") != null) { RadioButtonList rdbl = (RadioButtonList)e.Row.FindControl("SelectRadioButtonList1"); rdbl.SelectedIndexChanged += new EventHandler(rdbl_SelectedIndexChanged); } } } protected void rdbl_SelectedIndexChanged(object sender, EventArgs e) { RadioButtonList rdbl = (RadioButtonList)sender; this.SelectedRLText.Text = rdbl.SelectedItem.Text; }} // .aspx<asp:GridView ... <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" > <asp:ListItem Text="很好" Value="1" Selected="False" ></asp:ListItem> <asp:ListItem Text="较好" Value="2" Selected="False"></asp:ListItem> <asp:ListItem Text="尚可" Value="3" Selected="False"></asp:ListItem> <asp:ListItem Text="不好" Value="4" Selected="False"></asp:ListItem> </asp:RadioButtonList>........ // .aspx.csprotected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { RadioButtonList rbl = (RadioButtonList)sender; TextBox1.Text = rbl.SelectedItem.Text; } 关键是获得radiobuttionlist的引用 求助:请教各位高手,GridView中怎样实现点击标题正反排序? 我当项目组长,领导做一个OA,各位给点意见----------同时散分 怎样改变母版页的大小? 用Attributes.Add方法实现输入数据类型的控制 请问如何动态删除PLACEHOLDER中的控件?比如说最后一个? 新手:关于RedirectFromLoginPage的问题! 请教 !无法从web服务器获取项目文件 GridView方面的问题 一个函数调用的问题 小弟初涉.net,是因为要帮朋友作个程序。求教思路,主题 获取obj.style.position 问题 gridview中删除数据行的问题.
{Literal litForRadio = (Literal)e.Row.FindControl("litForRadio");
TextBox txtForRadio = (TextBox)e.Row.FindControl("txtForRadio");string outhtml = @"<input type=radio name=gditem{0}radio onclick=""if(this.checked)document.getElementById('{1}').value='好';"" />好<br>
<input type=radio name=gditem{0}radio onclick=""if(this.checked)document.getElementById('{1}').value='不好';"" />不好<br>";//.....
litForRadio.Text = string.Format(outhtml,e.Row.RowIndex,txtForRadio.ClientId);
}
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function getRankValue(obj)
{
document.getElementById("<%=tb.ClientID %>").value=obj.value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="rbtnRank" runat="server">
<asp:ListItem onclick="getRankValue(this)" Value="很好"></asp:ListItem>
<asp:ListItem onclick="getRankValue(this)" Value="较好"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="tb" runat="server"></asp:TextBox>
</div>
</form>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" datakeynames="ID" CommadName="Select" OnRowCreated="GridView1_RowCreated" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="SelectRadioButtonList1" runat="server" AutoPostBack="true" >
<asp:ListItem Text="很好" Value="1" Selected="False" ></asp:ListItem>
<asp:ListItem Text="较好" Value="2" Selected="False"></asp:ListItem>
<asp:ListItem Text="尚可" Value="3" Selected="False"></asp:ListItem>
<asp:ListItem Text="不好" Value="4" Selected="False"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ShowHeader="true" DataField="ID" HeaderText="ID" />
<asp:BoundField ShowHeader="true" DataField="name" HeaderText="姓名" />
</Columns>
</asp:GridView>
<span>评价:</span>
<asp:TextBox ID="SelectedRLText" runat="server" Text=""></asp:TextBox>
</div>
</form>
</body>
</html>using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
public class EntityTest
{
private int id;
public int ID
{
get
{ return this.id; }
set
{ this.id = value; }
}
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public EntityTest(int id, string name)
{
this.ID = id;
this.Name = name;
} }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
this.GridView1.DataSource = CreateList();
this.GridView1.DataBind();
} }
protected List<EntityTest> CreateList()
{
List<EntityTest> sourceList = new List<EntityTest> { new EntityTest(1, "aaa"), new EntityTest(2, "bbb"), new EntityTest(3, "ccc"), new EntityTest(4, "ddd") };
return sourceList;
} protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.FindControl("SelectRadioButtonList1") != null)
{
RadioButtonList rdbl = (RadioButtonList)e.Row.FindControl("SelectRadioButtonList1");
rdbl.SelectedIndexChanged += new EventHandler(rdbl_SelectedIndexChanged);
}
}
}
protected void rdbl_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rdbl = (RadioButtonList)sender;
this.SelectedRLText.Text = rdbl.SelectedItem.Text;
}}
<asp:GridView ...
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" >
<asp:ListItem Text="很好" Value="1" Selected="False" ></asp:ListItem>
<asp:ListItem Text="较好" Value="2" Selected="False"></asp:ListItem>
<asp:ListItem Text="尚可" Value="3" Selected="False"></asp:ListItem>
<asp:ListItem Text="不好" Value="4" Selected="False"></asp:ListItem>
</asp:RadioButtonList>
........
// .aspx.cs
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbl = (RadioButtonList)sender;
TextBox1.Text = rbl.SelectedItem.Text;
}