日期:2014-05-19  浏览次数:20401 次

$求助$ 求一循环语句 使得<a>标签能显示出SQL中一列的所有数据
求一循环语句   使得 <a> 标签能显示出SQL中一列的所有数据
现在 <a> 标签只能显示一条纪录
如何能让 <a> 标签显示出SQL中一列的所有纪录呢
求助高手
.aspx
<a   href= "# "> <%=str%> </a>

.cs
public   partial   class   ASP_Code_Question   :   System.Web.UI.Page
{
        public   void   Page_Load(object   sender,   EventArgs   e)
        {
                string   strSQL   =   "SELECT   [userID]FROM   User ";
                DataSet   ds   =   SqlHelper.ExecuteAdapter(SqlHelper.ConnM2D,   CommandType.Text,   strSQL,   null);
                str=ds.Tables[0].DefaultView[0].Row[ "userID "].ToString();
    }
      public   String   str;
}
高手请看看怎么写这条循环语句     能让 <a> 标签显示出所有的UserID
我现在代码需要怎么改正    

谢谢了
急!急!急!急!急!急!!!

------解决方案--------------------
aspx
<asp:PlaceHolder ID= "PlaceHolder1 " runat= "server "> </asp:PlaceHolder>

cs
foreach(DataRow row in ds.Tables[0].Rows)
{
string str = row[ "userID "].ToString();
HtmlAnchor ha = new HtmlAnchor();
ha.HRef = "# ";
ha.InnerText = str;
PlaceHolder1.Controls.Add(ha);
}
------解决方案--------------------
HTML:
<table>
<tbody id= "aa " runat=server>
<tr>

</tr>
</tbody>
</table>

后台:
for()
StringBuilder stringbuilder = new StringBuilder ( " ");
foreach(DataRow row in ds.Tables[0].Rows)
{

stringbuilder .Append( " <tr> ");
stringbuilder .AppendFormat( " <td> <a href= "连接页面 "> {0} </a> </td> ",row [ "userID "].ToString());
stringbuilder .Append( " </tr> ");
aa.innerhtml=stringbuilder .ToString();
}
------解决方案--------------------
<asp:repeater ID= "rpt " runat = "server " >
<ItemTemplate > <li/> <a href= "# "> <%#DataBinder.Eval(Container.DataItem, "f ") %> </a> </ItemTemplate>
</asp:repeater>


DataTable dt = new DataTable();
dt.Columns .Add ( new DataColumn ( "f ", typeof( String )));
DataRow row = dt.NewRow();
row[ "f "] = "xiao ";
dt.Rows.Add(row);
row = dt.NewRow();
row[ "f "] = "aa ";
dt.Rows.Add(row);

this.rpt.DataSource = dt;
this.rpt.DataBind();