aspx页面中动态创建控件

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 ouyang76cn 的 blog

<%@page language="c#"%>
<%@import namespace="system.data"%>
<%@import namespace="system.data.oledb"%>
<%@import namespace="system.text"%>

<style type="text/css">
   td.productdesc
   {
 font-family: verdana;
        font-size: small;
 color: #ff3333;
 width: 100%;
 vertical-align: top;
   }
</style>
<script language="c#" runat="server">

 hashtable hashproductname = new hashtable();
 hashtable hashproductdesc = new hashtable();

public void page_load(object obj,eventargs e)
{

 hashproductname[0] = "jalapeno dip" ;
 hashproductname[1] = "smoked sausage" ;
 hashproductname[2] = "shrimp fiesta" ;
 hashproductname[3] = "jerk chicken" ;
 hashproductname[4] = "beer-battered fish" ;
 hashproductname[5] = "bacon burger" ;
 hashproductname[6] = "sirloin tip" ;
 hashproductname[7] = "baked alaska" ;
 hashproductname[8] = "fried chicken" ;
 hashproductname[9] = "fresh garden salad" ;
 hashproductname[10] = "one pea" ;

 hashproductdesc[0] = "simmered in mayonaise and wine, this jalapeno dip will make your eyes water" ;
 hashproductdesc[1] = "mouth watering and delicious sausage" ;
 hashproductdesc[2] = "east coast's finest shrimp" ;
 hashproductdesc[3] = "a real island experience you will not forget" ;
 hashproductdesc[4] = "pabst blue ribbon and fish. wow!" ;
 hashproductdesc[5] = "big, juicy, and bursting with flavor" ;
 hashproductdesc[6] = "delicate cuts with no fat" ;
 hashproductdesc[7] = "fine dessert comprised of sponge cake topped with ice cream and covered with meringue. " ;
 hashproductdesc[8] = "country cookin'" ;
 hashproductdesc[9] = "crispy iceberg lettuce and a garden of vegtables" ;
 hashproductdesc[10] = "a single green pea that will leave you craving more" ;

 for (int i=0; i<=10; i++)
 {
   linkbutton lb5= new linkbutton();
   lb5.text = hashproductname[i].tostring();
   lb5.commandname = "products";
   lb5.cssclass = "productlinks";
   lb5.commandargument = i.tostring() ;
   lb5.command += new system.web.ui.webcontrols.commandeventhandler(onlinkclick);
   linklist.controls.add(lb5);
   linklist.controls.add(new literalcontrol("<br>"));
 }
}

private void onlinkclick(object o, system.web.ui.webcontrols.commandeventargs e)
{
 int recordid = int32.parse(e.commandargument.tostring());
 tablecellmessage.text="<b>"+hashproductname[recordid].tostring()+"</b><br><i>"+hashproductdesc[recordid].tostring()+"</i>";
}
</script>

<form runat="server">

<asp:table cellpadding=6 cellspacing=2 bordercolor="#dddddd" borderstyle=solid borderwidth=2 runat=server>
<asp:tablerow runat=server>
  <asp:tablecell id=linklist wrap=false backcolor="#ffffff" runat=server/>
  <asp:tablecell id="tablecellmessage" cssclass="productdesc" runat=server></asp:tablecell>
</asp:tablerow>
</asp:table>

</form>
<asp:label id="message" forecolor="red" runat="server"/>

本文关键:动态创建控件,aspx
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top