473,883 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic TreeView selection binding to DetailsView using sqlDataSource in ASP.NET 2.0

1 New Member
Hi Experts,

Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere.

Basically I have a TreeView Control which I have created programmaticall y. And I want to bind the selection of a TreeNode (which is a record) from the database) to a DetailsView which shows the datatable record for the selected TreeView node in the Details View.

I am using IDE : Visual Web Developer 2005 Express; OS= Windows XP Professional;
Language used VB.NET; Database being used MySQL Server 5.0, for my database, using MySQL Connector/ODBC 3.51 and also installed MYSQL Connector/Net 5.0.8.1


The TreeView appears to work when
'Declared the variable below
<script runat=server>
Public TreeNodeValue As String

[TreeView Code goes here, can be provided if requested]
' left out for clarity...

'Event Handler code to display TreeViewNode selection
Expand|Select|Wrap|Line Numbers
  1. Protected Sub TreeViewCommondata_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  2. TreeNodeValue = TreeViewCommondata.SelectedNode.Value
  3. Response.Write("You selected TreeViewNode value : " & _TreeViewCommondata.SelectedNode.Value)
  4. End Sub
  5.  
</script>

When at run time, when the TreeNode is selected the above Response.Write renders to the webpage with the selected TreeView control and displays the String for the TreeNode selected.

Now I want to bind the selected TreeView node to a DetailsView so I basically draggged SqlDatasource to webpage containing TreeViewcontrol and also dragged the DetalisView on this webpage. Configured the datasource for SQLDatasource to my MySQL database)


Also the markup is as follows:
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form id="form1" runat="server">
  3. <div> 
  4. <!-- The TreeView control associates the OnTreeNodePopulate method with an event handler named_
  5. Node_Populate --> 
  6. &nbsp;<asp:TreeView Runat="Server" ExpandImageUrl="Images/closed.gif" CollapseImageUrl="Images/open.gif" OnTreeNodePopulate="Node_Populate" ID="TreeViewCommondata" ImageSet="Simple" ShowLines="True" NodeWrap="True" Width="260px" OnSelectedNodeChanged="TreeViewCommondata_SelectedNodeChanged" OnDataBinding="TreeViewCommondata_SelectedNodeChanged" OnDataBound="TreeViewCommondata_SelectedNodeChanged">
  7. <Nodes>
  8. <asp:TreeNode Text="Common data" PopulateOnDemand=True Value="0" >
  9. </asp:TreeNode>
  10. </Nodes>
  11. <ParentNodeStyle Font-Bold="False" />
  12. <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
  13. <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
  14. VerticalPadding="0px" />
  15. <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="0px"
  16. NodeSpacing="0px" VerticalPadding="0px" />
  17. </asp:TreeView>
  18. &nbsp;&nbsp;
  19. </div>
  20. <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" BackColor="#CCCCCC"
  21. BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
  22. DataSourceID="SqlDataSource1" ForeColor="Black" Height="50px" Width="700px" style="left: 309px; position: absolute; top: 34px">
  23. <FooterStyle BackColor="#CCCCCC" />
  24. <EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  25. <RowStyle BackColor="White" />
  26. <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
  27. <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  28. </asp:DetailsView>
  29. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:bier_compact_test5ConnectionString %>"
  30. ProviderName="<%$ ConnectionStrings:bier_compact_test5ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM commondata WHERE Name=?TreeNodeValue">
  31. <SelectParameters>
  32. <asp:ControlParameter ControlID="TreeViewCommondata" Name="Name" PropertyName="SelectedValue"
  33. Type="String" />
  34. </SelectParameters>
  35. </asp:SqlDataSource>
  36. </form>
  37. </body>
  38.  
When I run the page I get the TreeView control on the webpage, however when I select a node I get the error:-
"ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.37-community-nt]You 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 mark-up and replace the ?TreeNodeValue with 'Field name' from the MySQL table a DetailsView 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, or is it a page life-cycle issue?
I have seen on some forums that this maybe a bug with MySQL connector regarding passing value parameters. However, I just do not have the knowledge at the moment for a workaround. Maybe using the ObjectDataSourc e object? I don’t know?

Maybe doing some not correct of missing something, probably straight forward for a experienced developers.

Any examples, pointers and help/guidance would be deeply appreciated.

Regards

Martin(MAK36)
Nov 1 '07 #1
2 5515
jhardman
3,406 Recognized Expert Specialist
Hi Martin,

Your question has been moved to the .NET Forum as it is not an appropriate question for the ASP Forum as per the Posting Guidelines.
The ASP Forum is for classic ASP and VBScript questions and answers, .NET and it's related components/languages are discussed in this forum.

Jared
Nov 2 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Suggest searching the site first to see if you an answer, we get many posts about treeviews.
Nov 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
5344
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be (filtered) dependent upon the selection in DDL1. I think this inevitably needs some code, but I'd be happy to be told otherwise! I have some code to handle OnSelectedIndexChanged for DDL1 that sets the FilterExpression associated with the...
2
2627
by: Dabbler | last post by:
In some cases I would like to allow a user to select a row from a GridView to update in another page using a DetailsView form (passing the key in QueryString). In other cases I would like to use the same DetailsView form to allow general edit/insert/delete functions with Paging=true. I can't figure out how to change the select statement from one case to the other, e.g. if I have an SqlDataSource with:
3
4079
by: chrisn | last post by:
Hi, (Using ASP.Net 2.0) I have a wizard control inside a detailsview control. When I attempt to call the InsertItem method on the DetailsView I get an error "ObjectDataSource 'ObjectDataSource1' has no values to insert. Check that the 'values' dictionary contains values." I have found I can suppress the error by placing a hidden field inside
2
2617
by: bmayer | last post by:
I am using a detail view and binding it to a sql data source (at some point in the future it will be an object data source). I have seen the article "Working with Data is ASP.NET 2.0 :: Customizing the Data Modification Interface", and its description of how to turn one of the fields into a template field, then add a drop down list. I want to do the same thing except I want two drop down lists, with the second one populating its values...
2
5044
by: David Lozzi | last post by:
Howdy, I have a DetailsView that when I fire the UpdateItem event, it doesn't update the data. The page reloads and the data is set back to the original. I'm using a Button to fire the UpdateItem event and then leaves the user a status stating that the event is updated, which does occur so i know the button is firing properly. I haven't tried InsertItem yet, going to set that up now. Any ideas why this is happening? My code is below. ...
1
4276
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end database from Access to SQL Server. So I go in to the SQLDataSource and modify it to connect to the SQL Server database. No problem. However, the DetailsView control does not seem to pick up the changes. When I click on the little shortcut menu (not...
4
15025
by: Mark Olbert | last post by:
I am struggling with trying to retrieve the value of an autoincrement identity field after a DetailsView Insert operation. The DetailsView is bound to an SqlDataSource control. So far as I can tell, nowhere in the arguments for either the Inserted event for the DetailsView or the Inserted event for the SqlDataSource control is the value stored. Adding a dummy bound column for the identity field to the DetailsView doesn't work, either. ...
0
1539
by: gsauns | last post by:
I have a DetailsView which is inside of a FormView. I lifted this DetailsView straight off another one of my pages, where it was working beautifully. Now I get this endlessly frustrating error message whenever I try to go into Edit mode: Specified argument was out of the range of valid values. Parameter name: index The DetailsView is actually inside an UpdatePanel, which is inside an Ajax Accordion, which is inside the FormView. Could...
0
4640
by: dayiku | last post by:
I am trying to retrieve values from a boundfield in a detailsview. protected void BtnViewDetails_Click(object sender, EventArgs e) { // get the gridviewrow from the sender so we can get the datakey we need Button btnDetails = sender as Button; GridViewRow row = (GridViewRow)btnDetails.NamingContainer; DropDownList ddl = ((DropDownList)dvVehicleDetail.FindControl("DropdownList1"));
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11118
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5791
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.