网络编程 
首页 > 网络编程 > 浏览文章

RadioButtonList绑定图片及泛型Dictionary应用

(编辑:jimmy 日期: 2025/12/27 浏览:3 次 )
本博文是让你学会读取站点某一目录的图片,掌握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应用
上一篇:ASP.NET的适配器设计模式(Adapter)应用详解
下一篇:利用委托把用户控件的值显示于网页案例应用
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap