婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 通過RadioButton對DataList控件進行單選實例說明

通過RadioButton對DataList控件進行單選實例說明

熱門標簽:百度ai地圖標注 同安公安400電話怎么申請流程 預測式外呼系統使用說明 申請400電話手續 蘋果手機凱立德地圖標注 電話機器人軟件銷售工作 合肥電銷外呼系統哪家公司做的好 南陽外呼系統定制化 玉林市機器人外呼系統哪家好
本例實現通過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 ListConstellation> GetConstellation()
{
ListConstellation> constellation = new ListConstellation>();
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模版內。
復制代碼 代碼如下:

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控件綁定數據
復制代碼 代碼如下:

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事件
復制代碼 代碼如下:

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>
您可能感興趣的文章:
  • 獲取DataList控件的主鍵和索引實用圖解
  • 動態加載用戶控件至DataList并為用戶控件賦值實例演示
  • Datalist控件使用存儲過程來分頁實現代碼
  • asp.net datalist 用法
  • DataList中TextBox onfocus調用后臺void靜態方法及獲取相應行數

標簽:臺州 海南 南京 淄博 揚州 南京 南昌 嘉興

巨人網絡通訊聲明:本文標題《通過RadioButton對DataList控件進行單選實例說明》,本文關鍵詞  通過,RadioButton,對,DataList,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《通過RadioButton對DataList控件進行單選實例說明》相關的同類信息!
  • 本頁收集關于通過RadioButton對DataList控件進行單選實例說明的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 水城县| 安达市| 宜黄县| 永丰县| 台南县| 盐源县| 石城县| 安泽县| 武陟县| 西昌市| 兴山县| 镇安县| 长宁县| 南平市| 辽阳市| 阳泉市| 保定市| 邹平县| 双鸭山市| 南宁市| 东城区| 鹤峰县| 苍溪县| 贵德县| 建水县| 黑水县| 克山县| 益阳市| 西林县| 徐州市| 林州市| 曲周县| 福建省| 阜新| 洪湖市| 曲周县| 苏尼特左旗| 贵溪市| 伊春市| 明水县| 沂南县|