Page code:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "RadioButtonListDemo.aspx.cs"
inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:radiobuttonlist id= "Radiobuttonlist_demo" runat= "Server" onselectedindexchanged= "RadioButtonList_Demo_" SelectedIndexChanged "
Autopostback= "true" >
</asp:RadioButtonList>
<br/>
<asp:image id= "image_show" runat= "Server"/>
</div>
</form>
</body>
Background code:
Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using CDataBase;
Using System.IO;
public partial class _default:system.web.ui.page
{
<summary>
Page load Events
</summary>
<param name= "Sender" > Control send Object </param>
<param name= "E" > Event object </param>
protected void Page_Load (object sender, EventArgs e)
{
Get the value of connectionstring
Response.Write ("<script>alert (' + sqlhelper.constring + ') </script>");
if (! IsPostBack)
{
To have the path system root directory under the Fuwa folder under the file path
String spath = Server.MapPath (Request.applicationpath + "/Fuwa/");
Get all the names below this path contains their path
string[] Sfiles = Directory.GetFiles (spath);
Loops the path of all files
foreach (String sfile in Sfiles)
{
Fetch file name
String sname = Path.getfilenamewithoutextension (sfile);
Take file name, include extension
String sfilename = Path.getfilename (sfile);
Establish the RadioButtonList of the Text/value, using the overloaded method of
ListItem Ritem = new ListItem (sname, Request.applicationpath + "/Fuwa/" + sfilename);
Add subkeys to RadioButtonList
RADIOBUTTONLIST_DEMO.ITEMS.ADD (Ritem);
}
To set the display arrangement of radio buttons in a RBL
Radiobuttonlist_demo.repeatdirection = RepeatDirection.Horizontal;
Radiobuttonlist_demo.repeatlayout = repeatlayout.table;
}
}
<summary>
Select Item Change Event
</summary>
<param name= "Sender" > Control send Object </param>
<param name= "E" > Event object </param>
protected void Radiobuttonlist_demo_selectedindexchanged (object sender, EventArgs e)
{
Image_show.imageurl = RadioButtonList_Demo.SelectedValue.ToString ();
}
}
Focus
Get the path to a directory under the site Directory
Using Server.MapPath (argurment)
Parameters using
Request.appliaction + "/directory Name/"
The meaning of this sentence is
Request a path under a directory under the server
All the file names under the path are finished
Through the directory object in System.IO
GetFiles (Request.appliaction) method
Only all file names under this directory can contain the extension
Path still need to use Request.application + "/file/" way to get
The note has been written very clearly.
You can practice.