求救:TREEVIEW在第一次加载数据后怎么改变不了其内容(100分)

  • 主题发起人 主题发起人 daoba
  • 开始时间 开始时间
D

daoba

Unregistered / Unconfirmed
GUEST, unregistred user!
我从数据库取出数据生成XMLDATASOURCE并绑定到TREEVIEW,可以正常显示树型结构,但是在这之后不管怎么改变数据库的内容并重新绑定都不能改变页面上TREEVIEW的显示值,研究了VIEWSTATE,即使把整个页面的VIEWSTATE都禁止掉还是不能解决此问题,快崩溃了,页面缓存一直清除不掉,刷新页面同样显示第一次加载时的信息。
请高手指教。小弟先在这里谢过了。
 
沉下去了,我自己顶一下。
我的TREEVIEW数据源是用动态生成的XML格式字符串,更新后将其赋值给一个LABEL可以看到字符串已经更新,但是在用此字符串绑定TREEVIEW是服务器用的是最初的数据,更奇怪的是用另一个不用帐号登录所取得的字符串数据源是同样的,说明服务器里保存有此段代码执行的结果,在客户端请求时直接回送了,怎么样才能让服务器内存实时更新,请大家赐教。同时附源码供大家参考。
public void Page_Load(Object sender, EventArgs E)
{
//<%@OutputCache Duration=&quot;1&quot;
VaryByParam=&quot;None&quot;%>
//Response.Expires = 0;
if(!IsPostBack)
{
Menu = &quot;&quot;;
if((Int32)Session.Contents[&quot;ClassId&quot;] > 2) //控制部门经理级别的只能管理本部门的菜单项
{
GetMenu(1);
}
else
{
GetMenu(0);
}
MenuSource.Data = Menu;
TreeViewMenu.DataBind();
}
for(int i=0;
i<TreeViewMenu.CheckedNodes.Count;
i++) //控制每次只有一个被选中的菜单项作为父菜单
{
TreeViewMenu.CheckedNodes.Checked = false;
}
//for(int i=0;
i<TreeViewMenu.Nodes.Count;
i++)
//{
// TreeViewMenu.Nodes.Checked = true;
//}
}
public void GetMenu(int nMenuid)
{

SqlConnection Conn = new SqlConnection(Application[&quot;DbConnStr&quot;].ToString());
SqlCommand Comm = new SqlCommand();
SqlDataReader dr;
Comm.Connection = Conn;
if((Int32)Session.Contents[&quot;ClassId&quot;] > 2) //控制部门经理级别的只能管理本部门的菜单项
{
Comm.CommandText = &quot;select MenuId,MenuLayer,LTrim(RTrim(MenuTitle)) as MenuTitle,Leaf,LTrim(RTrim(LinkIndex)) as
LinkIndex,LTrim(RTrim(Images)) as Images from oamenu where upmenuid=&quot;+ nMenuid +&quot;
and enabled=1 and DepartmentId=&quot;
+
Session.Contents[&quot;DepartmentId&quot;].ToString() + &quot;
order by leaf,menuid&quot;;
}
else
{
Comm.CommandText = &quot;select MenuId,MenuLayer,LTrim(RTrim(MenuTitle)) as MenuTitle,Leaf,LTrim(RTrim(LinkIndex)) as
LinkIndex,LTrim(RTrim(Images)) as Images from oamenu where upmenuid=&quot;+ nMenuid +&quot;
and enabled=1 order by leaf,menuid&quot;;
}
Comm.Connection.Open();
dr = Comm.ExecuteReader();

while(dr.Read())
{
if((Int32)dr[&quot;Leaf&quot;] == 1)
{
Menu = Menu + &quot;<menuitem value='&quot;
+ dr[&quot;MenuId&quot;] + &quot;' text='&quot;
+ dr[&quot;MenuTitle&quot;] + &quot;'></menuitem>&quot;;
}
else
{
Menu = Menu + &quot;<menuitem value='&quot;
+ dr[&quot;MenuId&quot;] + &quot;' text='&quot;
+ dr[&quot;MenuTitle&quot;] + &quot;'>&quot;;
GetMenu((Int32)dr[&quot;MenuId&quot;]);
Menu = Menu + &quot;</menuitem>&quot;;
}
}
dr.Close();
Conn.Close();
}
public void MenuChg(Object sender, EventArgs E)
{
SqlConnection Conn = new SqlConnection(Application[&quot;DbConnStr&quot;].ToString());
SqlCommand Comm = new SqlCommand();
SqlDataReader dr;
Comm.Connection = Conn;
Comm.Connection.Open();
Comm.CommandText = &quot;update OaMenu set MenuTitle='&quot;
+ MenuTitle.Text.Trim() + &quot;',LinkIndex='&quot;
+ LinkIndex.Text.Trim() +
&quot;',Images='&quot;
+ Images.Text.Trim() + &quot;' where MenuId=&quot;
+ MenuId.Text;
Comm.ExecuteScalar();
Conn.Close();
Result.Text = &quot;<font size=4>已经成功修改!</font>&quot;;
MenuId.Text = &quot;&quot;;
MenuTitle.Text = &quot;&quot;;
LinkIndex.Text = &quot;&quot;;
Images.Text = &quot;&quot;;
TreeViewMenu.Nodes.Clear();
//Response.Expires = 0;
Menu = &quot;&quot;;
//添加成功后刷新菜单
if((Int32)Session.Contents[&quot;ClassId&quot;] > 2) //控制部门经理级别的只能管理本部门的菜单项
{
GetMenu(1);
}
else
{
GetMenu(0);
}
Result.Text = Menu;
MenuSource.Data = Menu;
TreeViewMenu.DataSourceID = &quot;MenuSource&quot;;
TreeViewMenu.DataBind();
//ViewState[&quot;TreeViewMenu&quot;] = &quot;asdfjkljasdfas&quot;;
//Response.Expires = 0;
//Response.Redirect(&quot;MenuChg.aspx&quot;);
}
 
为何没人回应啊,自己再顶一下。
我的代码都通过,就是页面数据不能更新,后台数据库能更新,而且给TREEVIEW取的数据源字符串也都更新,就是TREEVIEW不能更新,郁闷啊。
 
不知你用的 TreeView 和我用的是不是一样的。
我的程序中也用了TreeView,下面是VB.NET的源码:
Sub CreatRoot(ByVal treeView1 As Microsoft.Web.UI.WebControls.TreeView, ByVal BH As String, ByRef NodeCount As Integer)
'建根节点
Dim TreeNode As New Microsoft.Web.UI.WebControls.TreeNode
Dim sqlstr As String = &quot;SELECT xm,BH,LJGZ FROM rmms WHERE BH='&quot;
& BH & &quot;' and NodeEmpty=true&quot;
Dim LConn As New OleDbConnection(OleDBStr & Server.MapPath(MDB))
Dim myCommand As New OleDbCommand(sqlstr, LConn)
LConn.Open()
Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
Try
If myReader.HasRows then

While myReader.Read()
TreeNode.NodeData = myReader(&quot;BH&quot;).ToString
TreeNode.Text = myReader(&quot;XM&quot;).ToString & &quot;
(编号:&quot;
& myReader(&quot;BH&quot;).ToString & &quot;,累计工资:&quot;
& myReader(&quot;LJGZ&quot;).ToString & &quot;)&quot;
treeView1.Nodes.Clear()
treeView1.Nodes.Add(TreeNode)
End While
myReader.Close()
LConn.Close()
NodeCount = 1
CreatChildNode(TreeNode, BH, NodeCount)
End If
Finally
myReader.Close()
LConn.Close()
End Try
End Sub 'Main
Sub CreatChildNode(ByVal TreeNode As Microsoft.Web.UI.WebControls.TreeNode, ByVal HYBH As String, ByRef NodeCount As Integer)
'建子节点
Dim sqlstr As String = &quot;SELECT xm,BH,LJGZ FROM rmms WHERE FBH='&quot;
& HYBH & &quot;' and NodeEmpty=true order by id &quot;
Dim LConn As New OleDbConnection(OleDBStr & Server.MapPath(MDB))
Dim aHYBH() As String
Dim i As Integer
Dim myCommand As New OleDbCommand(sqlstr, LConn)
LConn.Open()
Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
Try
If myReader.HasRows then
i = 0
While myReader.Read()
Dim CTreeNode As New Microsoft.Web.UI.WebControls.TreeNode
CTreeNode.NodeData = myReader(&quot;BH&quot;).ToString
CTreeNode.Text = myReader(&quot;XM&quot;).ToString & &quot;
(编号:&quot;
& myReader(&quot;BH&quot;).ToString & &quot;,累计工资:&quot;
& myReader(&quot;LJGZ&quot;).ToString & &quot;)&quot;
TreeNode.Nodes.AddAt(i, CTreeNode)
i = i + 1
CreatChildNode(CTreeNode, myReader(&quot;BH&quot;).ToString, NodeCount)
NodeCount = NodeCount + 1
End While
myReader.Close()
LConn.Close()
End If
Finally
myReader.Close()
LConn.Close()
End Try
End Sub
 
后退
顶部