台灣最具影響力的-資訊專家社群 - 讓您成為最有價值的IT專業人才
線上人數
901
 
會員總數:230298
接案會員:6772
文章總數:2320
討論主題:176101
歡迎您免費加入會員
討論區列表 >> ASP.NET >> 討論區!TreeView 無法顯示 !

[變換順序]
[我要回覆]
1


回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
討論區!TreeView 無法顯示 !
價值 : 10 QP  點閱數:1394 回應數:5

點圖分享到Plurk吧!
樓主

92404321
門外漢
0 6
96 12
發送站內信

不好意思請問!我做範例時!
點選後要讓TreeView 顯示!都會出現初始化字串的格式和開始於索引 0 的規格不相符
是資料庫的問題嗎?我是access要轉成sql的

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
'取得選取的項目
Dim uid As Integer = Me.GridView1.SelectedDataKey.Value

Me.ShowMsg(uid)
End Sub


Sub ShowMsg(ByVal MsgNO As String)
'顯示發言內容
Me.HiddenField1.Value = MsgNO
'建立子節點
Me.TreeView1.Nodes.Clear()
Dim TreeNode As TreeNode = buildMsgNode(Me.TreeView1.Nodes, MsgNO)
buildChildNode(TreeNode.ChildNodes, MsgNO)
Me.TreeView1.ExpandAll()
End Sub

'討論序入口
Function buildMsgNode(ByRef nodes As TreeNodeCollection, ByVal uid As Integer) As TreeNode
Dim ads As New SqlDataSource("~/app_data/討論區.mdf", "")
ads.SelectCommand = "select * from 討論區 where uid=" & uid
Dim dv As Data.DataView = ads.Select(New DataSourceSelectArguments)
Dim NewNode As New TreeNode
NewNode.Text = dv(0).Item("主題")
NewNode.Value = dv(0).Item("uid")
nodes.Add(NewNode)
Return NewNode
End Function

'討論序內容
Sub buildChildNode(ByRef nodes As TreeNodeCollection, ByVal uid As Integer)
Dim ads As New SqlDataSource("~/app_data/討論區.mdf", "")
ads.SelectCommand = "select * from 討論區 where 回應=" & uid & " order by uid "
Dim dv As Data.DataView = ads.Select(New DataSourceSelectArguments)
For i As Integer = 0 To dv.Count - 1
Dim NewNode As New TreeNode
NewNode.Text = dv(i).Item("主題")
NewNode.Value = dv(i).Item("uid")
buildChildNode(NewNode.ChildNodes, dv(i).Item("uid"))
nodes.Add(NewNode)
Next
End Sub

Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged

Me.HiddenField1.Value = Me.TreeView1.SelectedNode.Value

End Sub


End Class
本篇文章發表於2008-06-17 15:56
什麼是iT Power資訊報 2010年藍色小舖認證專家風雲榜完全名單
1樓
作者回應

92404321
檢舉此回應
補上ASPX
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>未命名頁面</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="uid" DataSourceID="ADS_forumList" Height="130px" Width="495px">
<Columns>
<asp:BoundField DataField="uid" HeaderText="uid" InsertVisible="False"
ReadOnly="True" SortExpression="uid" />
<asp:BoundField DataField="發言者" HeaderText="發言者" SortExpression="發言者" />
<asp:BoundField DataField="主題" HeaderText="主題" SortExpression="主題" />
<asp:BoundField DataField="內文" HeaderText="內文" SortExpression="內文" />
<asp:BoundField DataField="時間" HeaderText="時間" SortExpression="時間" />
<asp:BoundField DataField="回應" HeaderText="回應" SortExpression="回應" />
<asp:ButtonField CommandName="select" Text="選取" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ADS_forumList" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [討論區] WHERE [uid] = @uid"
InsertCommand="INSERT INTO [討論區] ([發言者], [主題], [內文], [時間], [回應]) VALUES (@發言者, @主題, @內文, @時間, @回應)"
SelectCommand="SELECT * FROM [討論區] WHERE ([回應] = @回應)"
UpdateCommand="UPDATE [討論區] SET [發言者] = @發言者, [主題] = @主題, [內文] = @內文, [時間] = @時間, [回應] = @回應 WHERE [uid] = @uid">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="回應" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="uid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="發言者" Type="String" />
<asp:Parameter Name="主題" Type="String" />
<asp:Parameter Name="內文" Type="String" />
<asp:Parameter Name="時間" Type="String" />
<asp:Parameter Name="回應" Type="Int32" />
<asp:Parameter Name="uid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="發言者" Type="String" />
<asp:Parameter Name="主題" Type="String" />
<asp:Parameter Name="內文" Type="String" />
<asp:Parameter Name="時間" Type="String" />
<asp:Parameter Name="回應" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:HiddenField ID="HiddenField1" runat="server" />
<br />
<asp:TreeView ID="TreeView1" runat="server" ImageSet="Faq" ShowLines="True">
</asp:TreeView>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="uid"
DataSourceID="ADS_DetailsView">
<EditItemTemplate>
uid:
<asp:Label ID="uidLabel1" runat="server" Text='<%# Eval("uid") %>' />
<br />
發言者:
<asp:TextBox ID="發言者TextBox" runat="server" Text='<%# Bind("發言者") %>' />
<br />
主題:
<asp:TextBox ID="主題TextBox" runat="server" Text='<%# Bind("主題") %>' />
<br />
內文:
<asp:TextBox ID="內文TextBox" runat="server" Text='<%# Bind("內文") %>' />
<br />
時間:
<asp:TextBox ID="時間TextBox" runat="server" Text='<%# Bind("時間") %>' />
<br />
回應:
<asp:TextBox ID="回應TextBox" runat="server" Text='<%# Bind("回應") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="更新" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="取消" />
</EditItemTemplate>
<InsertItemTemplate>
發言者:
<asp:TextBox ID="發言者TextBox" runat="server" Text='<%# Bind("發言者") %>' />
<br />
主題:
<asp:TextBox ID="主題TextBox" runat="server" Text='<%# Bind("主題") %>' />
<br />
內文:
<asp:TextBox ID="內文TextBox" runat="server" Text='<%# Bind("內文") %>' />
<br />
時間:
<asp:TextBox ID="時間TextBox" runat="server" Text='<%# Bind("時間") %>' />
<br />
回應:
<asp:TextBox ID="回應TextBox" runat="server" Text='<%# Bind("回應") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="插入" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="取消" />
</InsertItemTemplate>
<ItemTemplate>
uid:
<asp:Label ID="uidLabel" runat="server" Text='<%# Eval("uid") %>' />
<br />
發言者:
<asp:Label ID="發言者Label" runat="server" Text='<%# Bind("發言者") %>' />
<br />
主題:
<asp:Label ID="主題Label" runat="server" Text='<%# Bind("主題") %>' />
<br />
內文:
<asp:Label ID="內文Label" runat="server" Text='<%# Bind("內文") %>' />
<br />
時間:
<asp:Label ID="時間Label" runat="server" Text='<%# Bind("時間") %>' />
<br />
回應:
<asp:Label ID="回應Label" runat="server" Text='<%# Bind("回應") %>' />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="ADS_DetailsView" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [討論區] WHERE ([uid] = @uid)">
<SelectParameters>
<asp:ControlParameter ControlID="HiddenField1" Name="uid" PropertyName="Value"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>



本篇文章回覆於2008-06-17 16:01
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

92404321
檢舉此回應
應該是這兩段有問題
SQL資料庫裡可以這樣寫嗎?

'討論序入口
Function buildMsgNode(ByRef nodes As TreeNodeCollection, ByVal uid As Integer) As TreeNode
Dim ads As New SqlDataSource("~/app_data/討論區.mdf", "")
ads.SelectCommand = "select * from 討論區 where uid=" & uid
Dim dv As Data.DataView = ads.Select(New DataSourceSelectArguments)
Dim NewNode As New TreeNode
NewNode.Text = dv(0).Item("主題")
NewNode.Value = dv(0).Item("uid")
nodes.Add(NewNode)
Return NewNode
End Function

'討論序內容
Sub buildChildNode(ByRef nodes As TreeNodeCollection, ByVal uid As Integer)
Dim ads As New SqlDataSource("~/app_data/討論區.mdf", "")
ads.SelectCommand = "select * from 討論區 where 回應=" & uid & " order by uid "
Dim dv As Data.DataView = ads.Select(New DataSourceSelectArguments)
For i As Integer = 0 To dv.Count - 1
Dim NewNode As New TreeNode
NewNode.Text = dv(i).Item("主題")
NewNode.Value = dv(i).Item("uid")
buildChildNode(NewNode.ChildNodes, dv(i).Item("uid"))
nodes.Add(NewNode)
Next
End Sub



本篇文章回覆於2008-06-17 18:03
--未登入的會員無法查看對方簽名檔--
3樓
回應

小朱
捐贈 VP 給 小朱 檢舉此回應
http://www.connectionstrings.com/?carrier=sqlserver2005


本篇文章回覆於2008-06-17 19:44
--未登入的會員無法查看對方簽名檔--
4樓
作者回應

92404321
檢舉此回應
OK囉!


本篇文章回覆於2008-06-18 00:38
--未登入的會員無法查看對方簽名檔--
5樓
回應

topcat
捐贈 VP 給 topcat 檢舉此回應
TreeView要結合資料庫小喵有範例
請參考
http://www.dotblogs.com.tw/topcat/archive/2008/03/05/1234.aspx




本篇文章回覆於2008-06-18 08:25
--未登入的會員無法查看對方簽名檔--
[變換順序]
1
 

回覆
如要回應,請先登入.