前端:
<asp:DataList ID="dl_ej" runat="server" RepeatDirection="Horizontal" RepeatColumns="1" OnItemDataBound="dl_ej_DataBinding" HorizontalAlign="Left" >
<ItemTemplate>
<a class=p10 href="second.aspx?menu_id=<%#Eval("Menu_ID")%>" target="_blank"><%#Eval("Menu_Name")%></a>
<span>[<asp:Label ID="lblRecordCount" runat="server"></asp:Label>]</span><asp:Label ID="Label1" runat="server" CssClass="cClass" ></asp:Label>
</ItemTemplate>
</asp:DataList>
后端:
Label Label1 = (Label)e.Item.FindControl("Label1");
Label lblRecordCount = (Label)e.Item.FindControl("lblRecordCount");
string strSQL = "select * from Class where Menu_ParentLevel=" + this.dl_ej.DataKeys[e.Item.ItemIndex].ToString() + " and Menu_Lock=0 order by Menu_ID asc";
IDataReader dr = Class1.GetDataReader(strSQL);
SqlConnection con = Class1.DBconnection();
while (dr.Read())
{
string sql = "select * from wj_User where C_Three='" + dr["Menu_ID"] + "'";
SqlDataAdapter da1 = new SqlDataAdapter(sql, con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "Product");
string rows = ds1.Tables["Product"].Rows.Count.ToString();
Label1.Text += " <a class=p11 href='second.aspx?menu_id=" + dr["Menu_ParentLevel"] + "&subid=" + dr["Menu_ID"] + "' target=_blank>" + dr["Menu_Name"].ToString() + " [" + rows + "]</a><span class='font_1'></span> ";
da1.Dispose();
ds1.Dispose();
}
string sqlStr = "select * from wj_User where C_Two='" + this.dl_ej.DataKeys[e.Item.ItemIndex].ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter(sqlStr, con);
DataSet ds = new DataSet();
da.Fill(ds, "Product");
string num = ds.Tables["Product"].Rows.Count.ToString();
lblRecordCount.Text = num;
da.Dispose();
ds.Dispose();
con.Close();
con.Dispose();
效果如下: