DataList控件如何加入序号数字?
前台:
<asp:datalist id= "DataList1 " runat= "server " GridLines= "Vertical " RepeatColumns= "1 " Width= "100% "
BorderWidth= "0 ">
<ItemTemplate>
<table width= "100% " border= "0 " bordercolordark= "#ffffff " bordercolorlight= "#000000 " cellspacing= "0 "
cellpadding= "0 " bgcolor= "#000000 " align= "center ">
<tr align= "center " bgcolor= "#9bcde8 ">
<td height= "22 " bgcolor= "#d7e9f7 " align= "left " width= "35% "> <a href= 'javascript:SendNote( " <%#DataBinder.Eval(Container.DataItem, "User_ID ")%> ") ' alt= '点击可向此人发送短信 '> <%#DataBinder.Eval(Container.DataItem, "User_Name ")%> ( <%#DataBinder.Eval(Container.DataItem, "User_Logon ")%> ) </a> </td>
<td height= "22 " bgcolor= "#d7e9f7 " align= "left "> <%#DataBinder.Eval(Container.DataItem, "AppearDate ")%>
后台:
private void LoadDataList(int bbsid)
{
/*
string[] days={ "1 ", "2 ", "3 "};
DataList1.DataSource=days;
DataList1.DataBind();
*/
string sql= "PR_SelectBBS_Restore ";
SqlCommand cm=new SqlCommand(sql,conn.cn);
if(cm.Connection.State==ConnectionState.Closed)
cm.Connection.Open();
cm.CommandType=CommandType.StoredProcedure;
cm.Parameters.Add( "@BBS_ID ",SqlDbType.Int);
cm.Parameters[ "@BBS_ID "].Value=bbsid;
try
{
cm.ExecuteNonQuery();
SqlDataAdapter da=new SqlDataAdapter(cm);
DataSet ds=new DataSet();
da.Fill(ds, "BBS_Restore ");
DataList1.DataSource=ds;
DataList1.DataBind();
}
catch(SqlException e)
{
string err= "取资料有误!ErrorNumber= "+e.Number+ ",ErrorDescription= "+e.Message;
err=err.Replace( " ' ", "| ");
Response.Write(err);
}
finally
{
if(cm.Connection.State==ConnectionState.Open)
cm.Connection.Close();
cm=null;
conn=null;
}
}
上面代码是要显示论坛的回复信息,如我要在每个回复信息项里加入序号(如本站的1楼2楼),应该怎样加?请赐教
------解决方案-------------------- <%# Container.ItemIndex %>