lb.Click+= new System.Web.UI.WebControls.CommandEventHandler(OnLinkClick);看行不行?
解决方案 »
- 关于数据插入效率问题
- ?怎么生成1~1000的数字txt或者其他的文档?
- 有没有实现WindowsXP采用Royal主题时,状态栏的渐变颜色的控件?
- 有没有QQ宣传软件
- c#往mysql中插入图片为何无法插入 [Mysql 5.0(Win)]? mysql/c#高手请进
- 打包后执行程序出现的怪问题?
- 关于ACTIVEX控件的问题求大神解答
- 文件访问权限问题!
- 先装VS2005,再装VS2003,结果工程文件图标不能显示是VS8还是VS7.1的了,怎么办?
- .net中有多列的LISTBOX控件吗??
- Visual Studio.net序列号丢了,谁有,50分.
- 如何用C#在Windows Form 上实现邮件群发功能!
<%@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"/>
<tr>
<td nowrap="nowrap"><a id="lbtnFirstPage" href="javascript:__doPostBack('lbtnFirstPage','')" style="FONT-FAMILY: webdings">9</a><a id="lbtnPreviousPage" disabled="disabled" style="FONT-FAMILY: webdings">7</a></td><td id="Link"><span style="color:Red;font-size:9pt;font-weight:bold;">[1]</span> <a href="javascript:__doPostBack('_ctl2','')" style="color:Black;font-size:9pt;">2</a> <a href="javascript:__doPostBack('_ctl4','')" style="color:Black;font-size:9pt;">3</a> <a href="javascript:__doPostBack('_ctl6','')" style="color:Black;font-size:9pt;">4</a> <a href="javascript:__doPostBack('_ctl8','')" style="color:Black;font-size:9pt;">5</a> <a href="javascript:__doPostBack('_ctl10','')" style="color:Black;font-size:9pt;">6</a> <a id="lbafter" href="javascript:__doPostBack('lbafter','')" style="font-size:9pt;">...</a></td><td nowrap="nowrap"><a id="lbtnNextPage" href="javascript:__doPostBack('lbtnNextPage','')" style="FONT-FAMILY: webdings">8</a><a id="lbtnLastPage" href="javascript:__doPostBack('lbtnLastPage','')" style="FONT-FAMILY: webdings">:</a></td>
</tr>
</table>
<tr>
<td nowrap="nowrap"><td id="Link"><span style="color:Red;font-size:9pt;font-weight:bold;">[1]</span> <a href="javascript:__doPostBack('_ctl2','')" style="color:Black;font-size:9pt;">2</a> <a href="javascript:__doPostBack('_ctl4','')" style="color:Black;font-size:9pt;">3</a> <a href="javascript:__doPostBack('_ctl6','')" style="color:Black;font-size:9pt;">4</a> <a href="javascript:__doPostBack('_ctl8','')" style="color:Black;font-size:9pt;">5</a> <a href="javascript:__doPostBack('_ctl10','')" style="color:Black;font-size:9pt;">6</a> <a id="lbafter" href="javascript:__doPostBack('lbafter','')" style="font-size:9pt;">...</a></td>
</tr>
</table>
{
LinkButton lb = new LinkButton();
lb.CommandName = "numbutton";
lb.CommandArgument = i.ToString();
//lb.ID = i.ToString();
lb.Text = i.ToString();
cell.Controls.Add(lb);
}循環好像不行(個人看法)try:先用FindControl找到它
然後再增加事件
你的方法我试试先!!
其次,在pageload方法的if(!isPostBack)外面,调用刚才的方法,还好,代码写得还比较规范,改起来比较顺利,其实用Command事件或用Click事件都是可以的,再次感谢大家!