mak36
asked on
Binding dynamic TreeView node selction to a DetailsView using placeholder
Hi Experts,
I am a newbie to ASP.NET so may be I am doing something wrong or there is a bug somewhere.
I am using IDE : Visual Web Developer 2005 Exrpess; OS= Windows XP Professional;
Languange used VB.NET; Database being used MySQL Server 5.0 for my database, using MySQL Connector/ODBC 3.51.
Basically I have a TreeView Control which I have created programmatically.that I want to bind to a Details view which shows the datatable record for theslected TreeView node in the Details View.
This TreeView appears to work when
'Declared the variable below
<script runat=server>
Public TreeNodeValue As String
'TreeView Code goes here left out for clarity...
Protected Sub TreeViewCommondata_Selecte dNodeChang ed(ByVal sender As Object, ByVal e As System.EventArgs)
TreeNodeValue = TreeViewCommondata.Selecte dNode.Valu e
Response.Write("You selected TreeViewNode value : " & _TreeViewCommondata.Select edNode.Val ue)
End Sub
</script>
The above Response.Write renders to the webpage with the selected TreeView control and dsplays the String for the TreeNode selected.
Now I wanted to bind the selkected TreeViewnode to a DetailsView so basially draggged Sql Datasource to webpage containing TreeViewcontrol and also dragged the DetalisView on this webpage. Configured the datasource for SQLDatasource)
The mark up is as follows:
<body>
<form id="form1" runat="server">
<div>
<!-- The TreeView control associates the OnTreeNodePopulate method with an event handler named_
Node_Populate -->
<asp:TreeView Runat="Server" ExpandImageUrl="Images/clo sed.gif" CollapseImageUrl="Images/o pen.gif" OnTreeNodePopulate="Node_P opulate" ID="TreeViewCommondata" ImageSet="Simple" ShowLines="True" NodeWrap="True" Width="260px" OnSelectedNodeChanged="Tre eViewCommo ndata_Sele ctedNodeCh anged" OnDataBinding="TreeViewCom mondata_Se lectedNode Changed" OnDataBound="TreeViewCommo ndata_Sele ctedNodeCh anged">
<Nodes>
<asp:TreeNode Text="Common data" PopulateOnDemand=True Value="0" >
</asp:TreeNode>
</Nodes>
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</div>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
DataSourceID="SqlDataSourc e1" ForeColor="Black" Height="50px" Width="700px" style="left: 309px; position: absolute; top: 34px">
<FooterStyle BackColor="#CCCCCC" />
<EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:bier_com pact_test5 Connection String %>"
ProviderName="<%$ ConnectionStrings:bier_com pact_test5 Connection String.Pro viderName %>" SelectCommand="SELECT * FROM commondata WHERE Name=?TreeNodeValue">
<SelectParameters>
<asp:ControlParameter ControlID="TreeViewCommond ata" Name="Name" PropertyName="SelectedValu e"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
When I run the page I ge the Treeview on the webpage, however when I select a node I get the error:-
"ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.37-comm unity-nt]Y ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TreeNodeValue' at line 1"
However, if I hard code the markup and replace the ?TeeNodeValue with 'Filed name' from the MySQl table a DetalsView is displayed albeit fixed to that field.
I have seen previous example s on the Internet using SQL Server which uses @ as the placeholder and assumed it would be a matter of using ? for MySQL.
Maybe it's a postback thing I am not understanding,
I am obviously doing some not correct of missing something, prorblay straight forward for a Experets-Exhange Guru.
Any examples, pointers and help would be deply appreciated.
Regards
Martin(MAK36)
I am a newbie to ASP.NET so may be I am doing something wrong or there is a bug somewhere.
I am using IDE : Visual Web Developer 2005 Exrpess; OS= Windows XP Professional;
Languange used VB.NET; Database being used MySQL Server 5.0 for my database, using MySQL Connector/ODBC 3.51.
Basically I have a TreeView Control which I have created programmatically.that I want to bind to a Details view which shows the datatable record for theslected TreeView node in the Details View.
This TreeView appears to work when
'Declared the variable below
<script runat=server>
Public TreeNodeValue As String
'TreeView Code goes here left out for clarity...
Protected Sub TreeViewCommondata_Selecte
TreeNodeValue = TreeViewCommondata.Selecte
Response.Write("You selected TreeViewNode value : " & _TreeViewCommondata.Select
End Sub
</script>
The above Response.Write renders to the webpage with the selected TreeView control and dsplays the String for the TreeNode selected.
Now I wanted to bind the selkected TreeViewnode to a DetailsView so basially draggged Sql Datasource to webpage containing TreeViewcontrol and also dragged the DetalisView on this webpage. Configured the datasource for SQLDatasource)
The mark up is as follows:
<body>
<form id="form1" runat="server">
<div>
<!-- The TreeView control associates the OnTreeNodePopulate method with an event handler named_
Node_Populate -->
<asp:TreeView Runat="Server" ExpandImageUrl="Images/clo
<Nodes>
<asp:TreeNode Text="Common data" PopulateOnDemand=True Value="0" >
</asp:TreeNode>
</Nodes>
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
</div>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
DataSourceID="SqlDataSourc
<FooterStyle BackColor="#CCCCCC" />
<EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:bier_com
ProviderName="<%$ ConnectionStrings:bier_com
<SelectParameters>
<asp:ControlParameter ControlID="TreeViewCommond
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
When I run the page I ge the Treeview on the webpage, however when I select a node I get the error:-
"ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.37-comm
However, if I hard code the markup and replace the ?TeeNodeValue with 'Filed name' from the MySQl table a DetalsView is displayed albeit fixed to that field.
I have seen previous example s on the Internet using SQL Server which uses @ as the placeholder and assumed it would be a matter of using ? for MySQL.
Maybe it's a postback thing I am not understanding,
I am obviously doing some not correct of missing something, prorblay straight forward for a Experets-Exhange Guru.
Any examples, pointers and help would be deply appreciated.
Regards
Martin(MAK36)
ASKER
Yes,
The MYSQL ODBC Driver only supports positional paramters so "?" has to be used instead of any parmeters.
The MYSQL ODBC Driver only supports positional paramters so "?" has to be used instead of any parmeters.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob