aspx页面中动态创建控件

< %@page language="C#"%>
< %@import namespace="System.Data"%>
< %@import namespace="System.Data.OleDb"%>
< %@import namespace="System.Text"%>

 1<style type="text/css">   
 2TD.ProductDesc   
 3{   
 4font-family: Verdana;   
 5font-size: small;   
 6color: #FF3333;   
 7width: 100%;   
 8vertical-align: top;   
 9}   
10</style>
 1<script language="c#" runat="server">
 2
 3Hashtable hashProductName = new Hashtable();   
 4Hashtable hashProductDesc = new Hashtable(); 
 5
 6public void page_load(Object obj,EventArgs e)   
 7{ 
 8
 9hashProductName[0] = "Jalapeno Dip" ;   
10hashProductName[1] = "Smoked Sausage" ;   
11hashProductName[2] = "Shrimp Fiesta" ;   
12hashProductName[3] = "Jerk Chicken" ;   
13hashProductName[4] = "Beer-Battered Fish" ;   
14hashProductName[5] = "Bacon Burger" ;   
15hashProductName[6] = "Sirloin Tip" ;   
16hashProductName[7] = "Baked Alaska" ;   
17hashProductName[8] = "Fried Chicken" ;   
18hashProductName[9] = "Fresh Garden Salad" ;   
19hashProductName[10] = "One Pea" ; 
20
21hashProductDesc[0] = "Simmered in mayonaise and wine, this Jalapeno Dip will make your eyes water" ;   
22hashProductDesc[1] = "Mouth watering and delicious sausage" ;   
23hashProductDesc[2] = "East Coast's finest shrimp" ;   
24hashProductDesc[3] = "A real island experience you will not forget" ;   
25hashProductDesc[4] = "Pabst Blue Ribbon and Fish. Wow!" ;   
26hashProductDesc[5] = "Big, juicy, and bursting with flavor" ;   
27hashProductDesc[6] = "Delicate cuts with no fat" ;   
28hashProductDesc[7] = "Fine dessert comprised of sponge cake topped with ice cream and covered with meringue. " ;   
29hashProductDesc[8] = "Country cookin'" ;   
30hashProductDesc[9] = "Crispy iceberg lettuce and a garden of vegtables" ;   
31hashProductDesc[10] = "A single green pea that will leave you craving more" ; 
32
33for (int i=0; i<=10; i++)   
34{   
35LinkButton LB5= new LinkButton();   
36LB5.Text = hashProductName[i].ToString();   
37LB5.CommandName = "Products";   
38LB5.CssClass = "ProductLinks";   
39LB5.CommandArgument = i.ToString() ;   
40LB5.Command += new System.Web.UI.WebControls.CommandEventHandler(OnLinkClick);   
41LinkList.Controls.Add(LB5);   
42LinkList.Controls.Add(new LiteralControl("<br>"));   
43}   
44} 
45
46private void OnLinkClick(object O, System.Web.UI.WebControls.CommandEventArgs E)   
47{   
48int RecordId = Int32.Parse(E.CommandArgument.ToString());   
49tablecellMessage.Text="<b>"+hashProductName[RecordId].ToString()+"</b><br><i>"+hashProductDesc[RecordId].ToString()+"</i>";   
50}   
51</script>
1<form runat="server">
2<asp:table bordercolor="#DDDDDD" borderstyle="Solid" borderwidth="2" cellpadding="6" cellspacing="2" runat="server">
3<asp:tablerow runat="server">
4<asp:tablecell backcolor="#FFFFFF" id="LinkList" runat="server/" wrap="False">
5<asp:tablecell cssclass="ProductDesc" id="tablecellMessage" runat="server"></asp:tablecell>
6</asp:tablecell></asp:tablerow>
7</asp:table>
8</form>
1<asp:label forecolor="red" id="message" runat="server"></asp:label>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus