最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法

 更新時(shí)間:2016年05月18日 17:21:55   作者:楊明波(Leo Yang)  
這篇文章主要介紹了Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

看到一個(gè)網(wǎng)友,有論壇上問(wèn)及,動(dòng)態(tài)的生成checkbox控件,在文本框中輸入一個(gè)“花”字,點(diǎn)一下“生成”按鈕,就會(huì)在下面生成一個(gè)checkbox,它的text屬性是“花”。再輸入一個(gè)“鳥(niǎo)”,點(diǎn)一下按鈕,就會(huì)生成第二個(gè)checkbox控件,text屬性是“鳥(niǎo)”...

Insus.NET的解決方法很簡(jiǎn)單,就是每次在文本框輸入的值都存起來(lái),然后把這些數(shù)據(jù)綁定至一個(gè)CheckBoxList控件上就行了。

詳細(xì),先創(chuàng)建一個(gè)對(duì)象:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Letter
/// </summary>
namespace Insus.NET
{
public class Letter
{
private string _Name;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public Letter()
{
}
public Letter(string name)
{
this._Name = name;
}
}
} 

創(chuàng)建一個(gè)實(shí)體,這個(gè)實(shí)體你可以把它開(kāi)發(fā)成可以操作性,如添加,編輯,更新,刪除或是獲取數(shù)據(jù)集,等等...

在本例中,Insus.NET只實(shí)添加以及獲取數(shù)據(jù)的兩個(gè)方法:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for LetterEntity
/// </summary>
namespace Insus.NET
{
public class LetterEntity
{
private List<Letter> _Letter = new List<Letter>();
public void Add(Letter l)
{
this._Letter.Add(l);
}
public IEnumerable<Letter> Letters
{
get {
return this._Letter;
}
}
}
} 

萬(wàn)事俱備,只差A(yù)SPX的實(shí)現(xiàn)了,創(chuàng)建一個(gè)aspx的網(wǎng)頁(yè):

在ASPX.cs代碼頁(yè)中,你可以實(shí)現(xiàn)所需要的功能:

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 Default2 : System.Web.UI.Page
{
LetterEntity le = new LetterEntity();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Data_Binding();
}
le = TemporaryLetters;
}
private void Data_Binding()
{
this.CheckBoxList1.DataSource = le.Letters;
this.CheckBoxList1.DataTextField = "Name";
this.CheckBoxList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Letter l = new Letter();
if (!string.IsNullOrEmpty(this.TextBox1.Text.Trim()))
l.Name = this.TextBox1.Text.Trim();
le.Add(l);
TemporaryLetters = le;
Data_Binding();
}
public LetterEntity TemporaryLetters
{
get
{
if (Session["LetterEntity"] == null)
return new LetterEntity();
else
return (LetterEntity)Session["LetterEntity"];
}
set
{
Session["LetterEntity"] = value;
}
}
} 

你也許覺(jué)得很復(fù)雜,因?yàn)樯嫒氪鎯?chǔ)數(shù)據(jù)的問(wèn)題。如果你把數(shù)據(jù)直接存入數(shù)據(jù)庫(kù)的話,你可以在上面#6步中把填寫(xiě)的值存入數(shù)據(jù)庫(kù)中,在#4步中,去讀取數(shù)據(jù)庫(kù)的數(shù)據(jù)綁定給CheckBoxList控件即可。

以上所述是小編給大家介紹的Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法的相關(guān)知識(shí),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

茌平县| 阳新县| 高陵县| 湖北省| 潍坊市| 瑞丽市| 肥西县| 汤原县| 安阳市| 洛阳市| 成武县| 彭州市| 彰武县| 黑河市| 贵南县| 富源县| 信宜市| 营山县| 通城县| 彰武县| 碌曲县| 西林县| 芦溪县| 安徽省| 霍林郭勒市| 平阳县| 台中县| 晋州市| 眉山市| 建昌县| 巧家县| 宿松县| 顺义区| 紫阳县| 洛宁县| 壤塘县| 唐海县| 揭东县| 古田县| 黄浦区| 吴旗县|