首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

Oracle认证与考试 小论坛 - CSDN 技术社区,该怎么解决

2012-04-07 
Oracle认证与考试 小论坛 -- CSDN 技术社区protected void Page_Load(object sender, EventArgs e){if (!I

Oracle认证与考试 小论坛 -- CSDN 技术社区
protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  OracleConnection conn = new OracleConnection(Page_SQL_CONN_Entity);
  conn.Open();
  OracleCommand cmd = new OracleCommand("select * from sys_action_column", conn);
  OracleDataReader dr = cmd.ExecuteReader();
  while (dr.Read())
  {
  TreeNode tn = new TreeNode();
  tn.Text = dr[1].ToString();
  tn.Value = dr[0].ToString();
  tn.NavigateUrl = "#";
  AddNodes(tn);
  TreeView1.Nodes.Add(tn);
  }
  dr.Close();
  conn.Close();
  conn.Dispose();
  }
  }

  private void AddNodes(TreeNode tn)
  {
  OracleConnection conn = new OracleConnection(Page_SQL_CONN_Entity);
  conn.Open();
  OracleCommand cmd = new OracleCommand("select id,action_name from sys_action where action_column_id=" + tn.Value, conn);
  OracleDataReader dr = cmd.ExecuteReader();
  while (dr.Read())
  {
  TreeNode subtn = new TreeNode();
  subtn.Text = dr[1].ToString();
  subtn.Value = dr[0].ToString();
  subtn.NavigateUrl = "xxx.aspx?xx=" + subtn.Value;
  tn.ChildNodes.Add(subtn);
  }
  dr.Close();
  conn.Close();
  conn.Dispose();

以上代码实现了将数据库中的两个表动态的绑定到一个TreeView上,生成了一个二级树,现在我想把它改成生成xml文件
一样的产生一个二级菜单,然后绑定到mune控件上,请大家指导一下。

[解决办法]
up
[解决办法]
楼主的意思是把数据写成XML文件,然后把文件作为数据源给Menu吗? 我觉得这样就涉及到IO操作了,会影响速度。
[解决办法]
menu可以直接绑定xml文件么?

[解决办法]
考虑使用迭代数据源的方式,参考一下这段代码,是采用迭代数据源的方式实现了一个DataSource控件:

public class CLocationDataSource : HierarchicalDataSourceControl, IHierarchicalDataSource
{

public CLocationDataSource() : base() { }

// Return a strongly typed view for the current data source control.
private CLocationDataSourceView view = null;
protected override HierarchicalDataSourceView GetHierarchicalView(string viewPath)
{
// 这里是代码的关键,viewPath可以理解为用于获取子元素集合的父元素票据,例如父节点的Value
// 对根节点的viewPath为空字符串,要注意这里的问题
viewPath = string.IsNullOrEmpty(viewPath) ? m_StartPosition.ToString() : viewPath;
view = new CLocationDataSourceView(viewPath);
return view;
}

// This can be used declaratively. To enable declarative use, 
// override the default implementation of CreateControlCollection 
// to return a ControlCollection that you can add to.
protected override ControlCollection CreateControlCollection()
{
return new ControlCollection(this);
}
}


public class CLocationDataSourceView : HierarchicalDataSourceView
{

private string _viewPath;
public CLocationDataSourceView(string viewPath)
{
// 对根节点的处理
_viewPath = string.IsNullOrEmpty(viewPath) ? "0" : viewPath;

}

public override IHierarchicalEnumerable Select()
{
// 这里用代码实现数据源的迭代体


CLocationCollection collection = new CLocationCollection();
foreach (CLocation category in CLocation.GetCatalogs())
{
if (category.ParentID.ToString() == _viewPath)
collection.Add(category);
}

return collection;
}

}

通过这种方式实现了一个DataSource控件后,就可以把他拖拽到你的页面上,然后设置你的TreeView/Menu控件的DataSourceID属性为这个控件的ID值就可以了。

[解决办法]

探讨
menu可以直接绑定xml文件么?

热点排行