RadioButtonList binding picture and Generic Dictionary application _ practical Tips

Source: Internet
Author: User
Tags microsoft website
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.