问题描述
kecheng.aspx----------------<divstyle="width:700px;"><divstyle="float:left;width:300px;background:#f00;"><divid="show3d"runat="server"></div></div></div>kecheng.aspx.cs------------usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclasskecheng:System.Web.UI.Page{SqlConnectionmyconn;protectedvoidPage_Load(objectsender,EventArgse){myconn=newSqlConnection(ConnStr.GetConnectionStrings());//this.show3d.Controls.Add(newLiteralControl("<TABLEclass=showcellSpacing=0cellPadding=0><TBODY><TR><TDclass=show_1>d</TD><TDclass=show_2>fdgdsfg</TD><TR><TR><TDclass=show_1>d</TD><TDclass=show_2>fdgdsfg</TD><TR><TR><TDclass=show_1>d</TD><TDclass=show_2>fdgdsfg</TD><TR><TR><TDclass=show_1>d</TD><TDclass=show_2>fdgdsfg</TD><TR><TR><TDclass=show_1>d</TD><TDclass=show_2>fdgdsfg</TD><TR></TR></TBODY></TABLE>"));ShowClass1();}protectedvoidShowClass1(){stringsqlselect="selecttop3*from[Class]";DataSetmyds=newDataSet();SqlDataAdaptermysda=newSqlDataAdapter(sqlselect,myconn);mysda.Fill(myds,"class");stringli="";for(inti=0;i<=myds.Tables["class"].Rows.Count-1;i++){li+="<li>"+myds.Tables["class"].Rows[i]["C_title"].ToString()+"";}this.show3d.Controls.Add(newLiteralControl("<ul>"+li+"</ul"));}}获取的效果:<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><!--savedfromurl=(0033)http://localhost/hz1/kecheng.aspx--><HTMLxmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE></TITLE><METAhttp-equiv=Content-Typecontent="text/html;charset=utf-8"><METAcontent="MSHTML6.00.2900.3157"name=GENERATOR></HEAD><BODY><FORMid=form1name=form1action=kecheng.aspxmethod=post><DIV><INPUTid=__VIEWSTATEtype=hiddenvalue=/wEPDwUKLTk3NTAwMzQ3NWRkPHdya/c2tM+hJFfSRcwTdcQo1N4=name=__VIEWSTATE></DIV><DIVstyle="WIDTH:700px"><DIVstyle="BACKGROUND:#f00;FLOAT:left;WIDTH:300px"><DIVid=show3d><UL><LI>d<LI>d<LI>d</UL><div></LI></UL></DIV></DIV></FORM></DIV></BODY></HTML>郁闷!!!!兄弟们遇见过没?
解决方案
解决方案二:
li+="<li>"+myds.Tables["class"].Rows[i]["C_title"].ToString()+"</li>";
解决方案三:
for(inti=0;i<=myds.Tables["class"].Rows.Count-1;i++){li+="<li>"+myds.Tables["class"].Rows[i]["C_title"].ToString()+"";}改成for(inti=0;i<=myds.Tables["class"].Rows.Count-1;i++){li+="<li>"+myds.Tables["class"].Rows[i]["C_title"].ToString()+"</li>";}没有结束符
解决方案四:
protectedvoidShowClass1(){DataTablemyds=newDataTable();myds.Columns.Add("c_title");myds.Rows.Add(newobject[]{"d"});myds.Rows.Add(newobject[]{"d"});myds.Rows.Add(newobject[]{"d"});stringli="";for(inti=0;i<=myds.Rows.Count-1;i++){li+="<li>"+myds.Rows[i]["C_title"].ToString()+"</li>";}this.show3d.Controls.Add(newLiteralControl("<ul>"+li+"</ul>"));}
解决方案五:
提示那里出错???错误的信息在那里?