亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

通過(guò)RadioButton對(duì)DataList控件進(jìn)行單選實(shí)例說(shuō)明

 更新時(shí)間:2013年01月20日 10:45:47   作者:  
本例實(shí)現(xiàn)通過(guò)RadioButton對(duì)DataList控件進(jìn)行單選,aspx拉一個(gè)DataList控件,把RadioButton置于DataList的ItemTemplate模版內(nèi);在.aspx.cs內(nèi)為DataList控件綁定數(shù)據(jù),很實(shí)用的功能,感興趣的朋友可以了解下啊
本例實(shí)現(xiàn)通過(guò)RadioButton對(duì)DataList控件進(jìn)行單選。你可以參考下面演示。
 
準(zhǔn)備好一個(gè)星座對(duì)象,并定義好一個(gè)泛型List來(lái)存儲(chǔ)每一個(gè)星座名稱。
復(fù)制代碼 代碼如下:

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, "雙魚(yú)座");
constellation.Add(c);
return constellation;
}
}
}

在.aspx拉一個(gè)DataList控件,把RadioButton置于DataList的ItemTemplate模版內(nèi)。
復(fù)制代碼 代碼如下:

<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內(nèi)為DataList控件綁定數(shù)據(jù)
復(fù)制代碼 代碼如下:

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來(lái)實(shí)現(xiàn)onclick事件
復(fù)制代碼 代碼如下:

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

相關(guān)文章

  • 使用asp.net改變圖片顏色如灰色的變成彩色

    使用asp.net改變圖片顏色如灰色的變成彩色

    在網(wǎng)站上改變圖片的顏色,比如灰色的變成彩色,彩色的變成灰色,下面是經(jīng)過(guò)測(cè)試可行的解決方案
    2014-09-09
  • asp.net(c#)限制用戶輸入規(guī)定的字符和數(shù)字的代碼

    asp.net(c#)限制用戶輸入規(guī)定的字符和數(shù)字的代碼

    這幾天在看到一個(gè)網(wǎng)站的注冊(cè)的時(shí)候,就只允許輸入規(guī)定的字符和數(shù)字。我就好奇的寫了一個(gè)校驗(yàn)的代碼。呵呵 不知道對(duì)大家有沒(méi)有用。如果有用的話可以保存。沒(méi)有用就當(dāng)是看看以下了。
    2010-10-10
  • asp.net動(dòng)態(tài)加載自定義控件的方法

    asp.net動(dòng)態(tài)加載自定義控件的方法

    這篇文章主要介紹了asp.net動(dòng)態(tài)加載自定義控件的方法,涉及asp.net動(dòng)態(tài)加載控件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-04-04
  • 壓縮aspx頁(yè)面刪除多余空格的兩種方法

    壓縮aspx頁(yè)面刪除多余空格的兩種方法

    這篇文章主要介紹了壓縮aspx頁(yè)面移除多余空格的兩種方法,可以在發(fā)布頁(yè)面之前壓縮aspx,無(wú)須浪費(fèi)web server的cpu,需要的朋友可以參考下
    2014-02-02
  • 大早上更新了Visual Studio 2019  試用一下

    大早上更新了Visual Studio 2019 試用一下

    本文給大家分享一篇關(guān)于Visual Studio 2019 的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒,需要的朋友可以參考下
    2019-04-04
  • .NET?Core配置連接字符串和獲取數(shù)據(jù)庫(kù)上下文實(shí)例

    .NET?Core配置連接字符串和獲取數(shù)據(jù)庫(kù)上下文實(shí)例

    這篇文章介紹了.NET?Core配置連接字符串和獲取數(shù)據(jù)庫(kù)上下文實(shí)例的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • ASP.NET 獲取客戶端IP方法

    ASP.NET 獲取客戶端IP方法

    本文主要介紹了ASP.NET獲取客戶端IP方法,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • Aspx/Asp.net 防注入程序 V1.0

    Aspx/Asp.net 防注入程序 V1.0

    asp下有人寫了防注入的程序,這次看到了一個(gè)asp.net的特提供給大家參考。
    2009-10-10
  • Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作

    Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作

    眾所周知斷點(diǎn)對(duì)于Visual Studio調(diào)試過(guò)程是十分重要的,斷點(diǎn)的設(shè)置也是為了更好的進(jìn)行調(diào)試。下面這篇文章主要給大家介紹了關(guān)于Visual Studio Debug實(shí)戰(zhàn)教程之?dāng)帱c(diǎn)操作的相關(guān)資料,需要的朋友可以參考下
    2018-09-09
  • ASP.NET Razor模板引擎中輸出Html的兩種方式

    ASP.NET Razor模板引擎中輸出Html的兩種方式

    這篇文章主要介紹了ASP.NET Razor模板引擎中輸出Html的兩種方式,結(jié)合實(shí)例形式分析了Html.Raw與MvcHtmlString類輸出HTML的實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-08-08

最新評(píng)論