Repeater嵌套二级显示不正常(附图说明)
标题:Repeater嵌套二级显示不正常(附图说明)
描述:
大类的myNoBigClassName这一部分显示是正常的
小类的myNoSmallClassName我是参照大类的思路来做的,但是在显示的时候,总是不正常
具体效果如下:
HTML Code
<!--大类循环显示开始-->
<% if(myNoBigClassName != ""){ %>
<tr>
<td height="30" colspan="3"><%= myNoBigClassName %></td>
</tr>
<% } %>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td height="30">大类</td>
</tr>
<!--小类循环显示开坮-->
<% if(myNoSmallClassName != ""){ %>
<tr>
<td height="30" colspan="3"><%= myNoBigClassName %></td>
</tr>
<% } %>[i][/i]
<asp:Repeater ID="Repeater2" runat="server" DataSource='<%# BindSub(Convert.ToInt32(Eval("InfomationBigClass_ID")))%>'>
<ItemTemplate>
<tr>
<td height="30">小类</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<!--小类循环显示结束-->
</ItemTemplate>
</asp:Repeater>
<!--大类循环显示结束-->
C# Code
public partial class InfomationClassManage : MacBase
{
protected string myNoBigClassName = null;
protected string myNoSmallClassName = null;
protected void Page_Load(object sender, EventArgs e)
{
// 数据库链接
SqlConnection myConnection = new SqlConnection(strConnection);
myConnection.Open();
// 数据库查询
string mySql = "select * from Mac_InfomationBigClass";
SqlDataAdapter myAdapter = new SqlDataAdapter(mySql,myConnection);
// 查询结果填充到DataSet数据集
DataSet mySet = new DataSet();
myAdapter.Fill(mySet);
// 用DataSet数据集绑定控件
Repeater1.DataSource = mySet;
Repeater1.DataBind();
myNoBigClassName = Repeater1.Items.Count == 0 ? "提示:您还没有添加任何信息大类!" : "";
myConnection.Close();
}
protected DataTable BindSub(int nBigClassID)
{
// 数据库链接
SqlConnection myConnection = new SqlConnection(strConnection);
myConnection.Open();
// 数据库查询
string mySql = "select * from Mac_InfomationSmallClass where InfomationBigClass_ID = @nBigClassID";
SqlDataAdapter myAdapter = new SqlDataAdapter(mySql,myConnection);
// 查询结果填充到DataSet数据集
myAdapter.SelectCommand.Parameters.AddWithValue("nBigClassID", nBigClassID);
DataSet mySet = new DataSet();
myAdapter.Fill(mySet);
// 判断是否有记录存在
if (mySet.Tables[0].Rows.Count == 0)
{
myNoSmallClassName = "提示:你还没有添加任何信息小类!";
}
myConnection.Close();
return mySet.Tables[0];
}
}
------解决方案--------------------C# code
// 判断是否有记录存在
if (mySet.Tables[0].Rows.Count == 0)
{
myNoSmallClassName = "提示:你还没有添加任何信息小类!";
}
myConnection.Close();