RadioButtonList綁定圖片及泛型Dictionary應(yīng)用
更新時間:2013年02月07日 11:23:57 作者:
讀取站點某一目錄的圖片,需要掌握LINQ與泛型Dictionary<TKey,TValue>的使用,本文將介紹RadioButtonList綁定圖片的實現(xiàn),感興趣的朋友可以了解下,或許對你有所幫助
本博文是讓你學會讀取站點某一目錄的圖片,掌握LINQ與泛型Dictionary<TKey,TValue>的使用。
首先準備好幾張圖片存在站點某一目錄之下,本例中的存儲圖片的目錄名為MsSiteImages,圖片你可以從微軟網(wǎng)站下載http://windows.microsoft.com/en-US/windows/home
我們寫一個泛型數(shù)據(jù)集,將存儲目錄的圖片信息:
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)建一個網(wǎng)頁,并拉RadioButtonList控件進入網(wǎng)頁:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
寫一個方法,用來綁定數(shù)據(jù)給RadioButtonList控件,其中一個綁定類別,你可以從下面地址下載 ,解壓之后,把InsusListControlUtility.dll放入站點的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();
}
運行網(wǎng)頁的效果:
首先準備好幾張圖片存在站點某一目錄之下,本例中的存儲圖片的目錄名為MsSiteImages,圖片你可以從微軟網(wǎng)站下載http://windows.microsoft.com/en-US/windows/home
我們寫一個泛型數(shù)據(jù)集,將存儲目錄的圖片信息:
復(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)建一個網(wǎng)頁,并拉RadioButtonList控件進入網(wǎng)頁:
復(fù)制代碼 代碼如下:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
寫一個方法,用來綁定數(shù)據(jù)給RadioButtonList控件,其中一個綁定類別,你可以從下面地址下載 ,解壓之后,把InsusListControlUtility.dll放入站點的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();
}
運行網(wǎng)頁的效果:
您可能感興趣的文章:
- 如何為CheckBoxList和RadioButtonList添加滾動條
- ASP.NET中RadioButtonList綁定后臺數(shù)據(jù)后觸發(fā)點擊事件
- ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
- jquery判斷RadioButtonList和RadioButton中是否有選中項示例
- js獲取RadioButtonList的Value/Text及選中值等信息實現(xiàn)代碼
- javascript判斷是否有對RadioButtonList選項選擇
- ASP.NET jQuery 實例16 通過控件CustomValidator驗證RadioButtonList
- JQuery中對服務(wù)器控件 DropdownList, RadioButtonList, CheckboxList的操作總結(jié)
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標簽后的value和text值
- ASP.NET控件之RadioButtonList詳解
相關(guān)文章
asp.net 使用Response.Filter 過濾非法詞匯
一般信息發(fā)布網(wǎng)站,論壇等均具有實現(xiàn)非法詞匯過濾功能,即當用戶錄入非法詞匯時,進行替換,使其無法顯示到頁面上,針對此種功能,通常采用的時,在讀取時,在讀到非法詞匯后,進行替換。2010-03-03
MVC HtmlHelper擴展類(PagingHelper)實現(xiàn)分頁功能
這篇文章主要為大家詳細介紹了MVC HtmlHelper擴展,實現(xiàn)分頁功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
ASP.NET/C#中如何調(diào)用動態(tài)鏈接庫DLL
這篇文章主要為大家詳細介紹了ASP.NET/C#中如何調(diào)用動態(tài)鏈接庫DLL,感興趣的小伙伴們可以參考一下2016-03-03

