RadioButtonList绑定图片及泛型Dictionary应用

要成功,就要长期等待而不焦躁,态度从容却保持敏锐,不怕挫折且充满希望。早安!减少蜗居时间,亲近大自然。
本博文是让你学会读取站点某一目录的图片,掌握LINQ与泛型Dictionary<TKey,TValue>的使用。首先准备好几张图片存在站点某一目录之下,本例中的存储图片的目录名为MsSiteImages,图片你可以从微软网站下载http://windows.microsoft.com/en-US/windows/home
我们写一个泛型数据集,将存储目录的图片信息:
 
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;
}

创建一个网页,并拉RadioButtonList控件进入网页:
 
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>

写一个方法,用来绑定数据给RadioButtonList控件,其中一个绑定类别,你可以从下面地址下载 ,解压之后,把InsusListControlUtility.dll放入站点的BIN目录中。
 
private void Data_Binding()
{
Insus.NET.InsusListControlUtility objList = new Insus.NET.InsusListControlUtility();
objList.RadioButtonListParse(this.RadioButtonList1, GetData(), "value", "key");
}

在网页的Page_Load中,引用上面的Data_Binding()方法:
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}

运行网页的效果:

到此这篇关于RadioButtonList绑定图片及泛型Dictionary应用就介绍到这了。但不要放纵自己的欲望,那犹如一滩漩涡,会将你卷入无底深渊。真正的青春应该学会掌握方向。更多相关RadioButtonList绑定图片及泛型Dictionary应用内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
自写一个模仿Dictionary与Foreach的实现及心得总结

C#中Dictionary几种遍历的实现代码

.Net中的弱引用字典WeakDictionary和ConditionalWeakTable介绍