This blog is for you to learn to read the pictures of a certain directory of the site, to master the use of LINQ and Generic dictionary<tkey,tvalue>.
First prepare several pictures exist under a certain directory of the site, in this case, the catalog name of the stored picture is mssiteimages, pictures you can download from the Microsoft website http://windows.microsoft.com/en-US/windows/home
We write a generic dataset that will store picture information for the directory:
Copy Code code as follows:
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"))
by 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;
}
Create a Web page and pull the RadioButtonList control into the Web page:
Copy Code code as follows:
<asp:radiobuttonlist id= "RadioButtonList1" runat= "Server" ></asp:RadioButtonList>
Write a method to bind the data to the RadioButtonList control, one of the binding categories, you can download from the following address, after decompression, put the InsusListControlUtility.dll into the site's Bin directory.
Copy Code code as follows:
private void Data_binding ()
{
Insus.NET.InsusListControlUtility objlist = new Insus.NET.InsusListControlUtility ();
Objlist.radiobuttonlistparse (this. RadioButtonList1, GetData (), "value", "key");
}
In the Page_Load of the Web page, refer to the Data_binding () method above:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
Data_binding ();
}
The effect of running a Web page: