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

RadioButtonList綁定圖片及泛型Dictionary應(yīng)用

 更新時(shí)間:2013年02月07日 11:23:57   作者:  
讀取站點(diǎn)某一目錄的圖片,需要掌握LINQ與泛型Dictionary<TKey,TValue>的使用,本文將介紹RadioButtonList綁定圖片的實(shí)現(xiàn),感興趣的朋友可以了解下,或許對(duì)你有所幫助
本博文是讓你學(xué)會(huì)讀取站點(diǎn)某一目錄的圖片,掌握LINQ與泛型Dictionary<TKey,TValue>的使用。

首先準(zhǔn)備好幾張圖片存在站點(diǎn)某一目錄之下,本例中的存儲(chǔ)圖片的目錄名為MsSiteImages,圖片你可以從微軟網(wǎng)站下載http://windows.microsoft.com/en-US/windows/home
我們寫一個(gè)泛型數(shù)據(jù)集,將存儲(chǔ)目錄的圖片信息:
復(fù)制代碼 代碼如下:

View Code
private Dictionary<int, string> GetData()
{
Dictionary<int, string> dic = new Dictionary<int, string>();
int i = 0;
System.IO.FileInfo fi;
var Images =
from f in System.IO.Directory.GetFiles(Server.MapPath("MsSiteImages"))
orderby f descending
select f;
foreach (var filename in Images)
{
fi = new System.IO.FileInfo(filename);
dic.Add(i, "<img src='" + "MsSiteImages/" + fi.Name + "' alt='" + fi.Name +
"' title='" + fi.Name + "'/>");
i++;
}
return dic;
}

創(chuàng)建一個(gè)網(wǎng)頁,并拉RadioButtonList控件進(jìn)入網(wǎng)頁:
復(fù)制代碼 代碼如下:

<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>

寫一個(gè)方法,用來綁定數(shù)據(jù)給RadioButtonList控件,其中一個(gè)綁定類別,你可以從下面地址下載 ,解壓之后,把InsusListControlUtility.dll放入站點(diǎn)的BIN目錄中。
復(fù)制代碼 代碼如下:

private void Data_Binding()
{
Insus.NET.InsusListControlUtility objList = new Insus.NET.InsusListControlUtility();
objList.RadioButtonListParse(this.RadioButtonList1, GetData(), "value", "key");
}

在網(wǎng)頁的Page_Load中,引用上面的Data_Binding()方法:
復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}

運(yùn)行網(wǎng)頁的效果:

相關(guān)文章

最新評(píng)論