日期:2014-05-17  浏览次数:20563 次

利用Repeater控件显示主-从关系数据表 出现错误,请帮忙分析
利用Repeater控件显示主-从关系数据表
页面代码:
  <asp:repeater id="ParentRepeater" runat="server" 
  onitemcreated="ParentRepeater_ItemCreated">
  <ItemTemplate>
  <tr>
  <td style="display:block;PADDING-LEFT: 15px;" height="32" background="images/LeftBg.jpg" id="cellbar<%# Container.ItemIndex%>" onclick="menuClick( 'submenu<%# Container.ItemIndex %>','cellbar<%# Container.ItemIndex %>')">
  <img src="images/i15_fav.gif" border="0" align="middle" /><b><font color="#00000">&nbsp;<%# DataBinder.Eval(Container.DataItem,"project_name") %></font></b>
  </td>
</tr>
<tr>
<td>
<span style="display: block;background-color:#e6f3fc;PADDING-LEFT: 15px;" id="submenu<%# Container.ItemIndex %>">
<asp:repeater id="ChildRepeater" runat="server" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("Operation") %>'>
<itemtemplate>
<img src="images/right.gif" border="0" align="middle" /> 
  <a style="height:18px" href='<%# DataBinder.Eval(Container.DataItem,"OBJ_NAME") %>' target="mainpage"
onclick='showPosition("<%# ProjectName %> → <%# DataBinder.Eval(Container.DataItem,"action_name")%>");'><%# DataBinder.Eval(Container.DataItem,"action_name")%>
</a> <br />
</itemtemplate>
</asp:repeater>
</span>
</td>
</tr>
  </ItemTemplate>
  </asp:repeater>

CS代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

public partial class LeftMenu : System.Web.UI.Page
{
  private string projectName;
  //protected System.Web.UI.WebControls.Repeater ParentRepeater;

  public string ProjectName
  {
  get { return projectName; }
  }

  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  string sql;
  MySqlConnection conn = new MySqlConnection();
  conn.ConnectionString = ConfigurationManager.ConnectionStrings["dlxjConnectionString"].ConnectionString;
  conn.Open();

  sql = string.Format("select project_id,project_name from projectinfo");
  MySqlDataAdapter myda = new MySqlDataAdapter(sql, conn);
  DataSet myds = new DataSet();
  myda.Fill(myds, "project");

  //sql = string.Format("select o.OBJ_ID,o.PROJECT_ID,o.ACTION_NAME,OBJ_NAME FROM objectinfo o,userprivates u,privategroup p WHERE u.Privates_ID=p.Private_ID AND p.Obj_ID=o.OBJ_ID AND u.User_ID='{0}'" , Session["UserBh"].ToString());
  sql = string.Format("select o.OBJ_ID,o.PROJECT_ID,o.ACTION_NAME,OBJ_NAME FROM objectinfo o,userprivates u,privategroup p WHERE u.Privates_ID=p.Private_ID AND