现在我再gridview的模版列中建立了一个radiobuttonlist,添加了 "很好","较好","可以","尚可","不好",几个项目,现在我想实现的是当我点很好的时候textbox框里面显示很好,当我点击较好的时候textbox框里显示较好,大家看清楚哦~是radiobuttonlist,不是radiobutton。请教如何取值~~~谢谢~~

解决方案 »

  1.   

    用for循环给radiobuttonlist每一项增加一个onclick事件test('很好'),把值传过去给textbox
      

  2.   

    用for循环给radiobuttonlist每一项增加一个onclick事件脚本test('很好'),把值传过去给textbox
      

  3.   

    模版列的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);
    }
      

  4.   

    <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>
      

  5.   

    花了一个小时给你做了个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;
       }}
      

  6.   

    // .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.cs
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           RadioButtonList rbl = (RadioButtonList)sender;
           TextBox1.Text = rbl.SelectedItem.Text;

       }
      

  7.   

    关键是获得radiobuttionlist的引用