第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

RadioButton置于DataList實(shí)現(xiàn)單選

標(biāo)簽:
JavaScript

本例实现通过RadioButton对DataList控件进行单选。你可以参考下面演示。


准备好一个星座对象,并定义好一个泛型List来存储每一个星座名称。

Constelltion.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;/// <summary>/// Summary description for Constellation/// </summary>namespace Insus.NET{    public class Constellation    {        private int _ID;        private string _Name;        public int ID        {            get { return _ID; }            set { _ID = value; }        }        public string Name        {            get { return _Name; }            set { _Name = value; }        }        public Constellation()        {            //            // TODO: Add constructor logic here            //        }        public Constellation(int id, string name)        {            this._ID = id;            this._Name = name;        }        public List<Constellation> GetConstellation()        {            List<Constellation> constellation = new List<Constellation>();            Constellation c = new Constellation(1, " 白羊座");            constellation.Add(c);            c = new Constellation(2, "金牛座");            constellation.Add(c);            c = new Constellation(3, "双子座");            constellation.Add(c);            c = new Constellation(4, "巨蟹座");            constellation.Add(c);            c = new Constellation(5, "狮子座");            constellation.Add(c);            c = new Constellation(6, "处女座");            constellation.Add(c);            c = new Constellation(7, "天秤座 ");            constellation.Add(c);            c = new Constellation(8, "天蝎座");            constellation.Add(c);            c = new Constellation(9, "射手座");            constellation.Add(c);            c = new Constellation(10, "摩羯座");            constellation.Add(c);            c = new Constellation(11, "水瓶座");            constellation.Add(c);            c = new Constellation(12, "双鱼座");            constellation.Add(c);            return constellation;        }    }}


在.aspx拉一个DataList控件,把RadioButton置于DataList的ItemTemplate模版内。

View Code

 <asp:DataList ID="DataListConstellation" runat="server" Width="100" CellPadding="0" CellSpacing="0">                <ItemStyle BorderWidth="1" />                <ItemTemplate>                    <table>                        <tr>                            <td>                                <asp:RadioButton ID="RadioButtonSelect" runat="server" onclick="SelectedRadio(this);" /></td>                            <td><%# Eval("ID") %></td>                            <td><%# Eval("Name") %></td>                        </tr>                    </table>                </ItemTemplate>            </asp:DataList>


在.aspx.cs内为DataList控件绑定数据:

View Code

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Insus.NET;public partial class _Default : System.Web.UI.Page{    Constellation objConstellation = new Constellation();        protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)            Data_Binding();    }    private void Data_Binding()    {        this.DataListConstellation.DataSource = objConstellation.GetConstellation();        this.DataListConstellation.DataBind();    }}


最后,我们写一段Javascript来实现onclick 事件。

View Code

 <script type="text/javascript">        function SelectedRadio(rb) {            var gv = document.getElementById("<%=DataListConstellation.ClientID%>");            var rbs = gv.getElementsByTagName("input");            var row = rb.parentNode.parentNode;            for (var i = 0; i < rbs.length; i++) {                if (rbs[i].type == "radio") {                    if (rbs[i].checked && rbs[i] != rb) {                        rbs[i].checked = false;                        break;                    }                }            }        }    </script>


 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消