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ǔ)目錄的圖片信息:
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)頁:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
寫一個(gè)方法,用來綁定數(shù)據(jù)給RadioButtonList控件,其中一個(gè)綁定類別,你可以從下面地址下載 ,解壓之后,把InsusListControlUtility.dll放入站點(diǎn)的BIN目錄中。
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()方法:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}
運(yùn)行網(wǎng)頁的效果:
首先準(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)頁的效果:
您可能感興趣的文章:
- 如何為CheckBoxList和RadioButtonList添加滾動(dòng)條
- ASP.NET中RadioButtonList綁定后臺(tái)數(shù)據(jù)后觸發(fā)點(diǎn)擊事件
- ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
- jquery判斷RadioButtonList和RadioButton中是否有選中項(xiàng)示例
- js獲取RadioButtonList的Value/Text及選中值等信息實(shí)現(xiàn)代碼
- javascript判斷是否有對(duì)RadioButtonList選項(xiàng)選擇
- ASP.NET jQuery 實(shí)例16 通過控件CustomValidator驗(yàn)證RadioButtonList
- JQuery中對(duì)服務(wù)器控件 DropdownList, RadioButtonList, CheckboxList的操作總結(jié)
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標(biāo)簽后的value和text值
- ASP.NET控件之RadioButtonList詳解
相關(guān)文章
ASP.NET網(wǎng)站管理系統(tǒng)退出 清除瀏覽器緩存,Session的代碼
管理系統(tǒng)退出登陸后,將網(wǎng)址重新輸入后還會(huì)看到用戶登陸后的界面,為了解決這個(gè)問題,我采用了以下方法,需要的朋友可以參考下2012-05-05
如何在.Net6 web api中記錄每次接口請(qǐng)求的日志
.net6有自帶的logging組件,還有很多優(yōu)秀的開源log組件,如NLog,serilog,這里我們使用serilog組件來構(gòu)建日志模塊,這篇文章主要介紹了如何在.Net6 web api中記錄每次接口請(qǐng)求的日志,需要的朋友可以參考下2023-06-06
ASP.NET 根據(jù)漢字獲取漢字拼音的首字母(含多音字)
本文分享了一個(gè)函數(shù),這個(gè)函數(shù)可以根據(jù)漢字的字符串獲取其拼音的首字母,以便我們?cè)趯?shí)際開發(fā)中使用。2016-04-04
ASP.NET Core Controller與IOC結(jié)合問題整理
在本篇文章里小編給大家整理了一篇關(guān)于ASP.NET Core Controller與IOC結(jié)合問題整理內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2021-01-01
ASP.NET2.0 WebRource,開發(fā)微調(diào)按鈕控件
ASP.NET2.0 WebRource,開發(fā)微調(diào)按鈕控件...2006-09-09
asp.net DataList與Repeater用法區(qū)別
Repeater比DataList要好一些,如果不是很大數(shù)據(jù)量的話,這點(diǎn)差別是體現(xiàn)不來的。2009-12-12
ASP.NET站點(diǎn)導(dǎo)航應(yīng)用詳解
這篇文章主要內(nèi)容是ASP.NET站點(diǎn)導(dǎo)航,主要包括站點(diǎn)導(dǎo)航以及動(dòng)態(tài)修改內(nèi)存中的站點(diǎn)地圖,感興趣的小伙伴們可以參考一下2015-09-09
ASP.NET Core 2.1 使用Docker運(yùn)行的方法步驟
這篇文章主要介紹了ASP.NET Core 2.1 使用Docker運(yùn)行的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07

