Welcome Guest Search | Active Topics | Sign In | Register

sql server dataset Options
Kjell Ek
Posted: Tuesday, April 14, 2009 4:19:57 PM
Rank: Advanced Member
Groups: Member

Joined: 4/14/2009
Posts: 33
Having recently found you and are interested primarily by EO.Web Controls Menu with the cross frame support

Is there a working example how to bind EO.Web Controls Menu to a sql server dataset like:

Code: Visual Basic.NET
Dim SelectCommand As String = "SELECT NodeId, ParentNodeId, sidnamn, LookId, RightIcon, NavigateUrl, target from sidor Order By NodeId ASC"
MyDataAdapter = New SqlDataAdapter(SelectCommand, MyConnection)

Dim DS As New DataSet()
MyDataAdapter.Fill(DS)


Have try samples "Data Binding", but may not work .....
eo_support
Posted: Tuesday, April 14, 2009 4:29:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Have you checked this sample?

http://demo.essentialobjects.com/Default.aspx?path=Menu\menu_programming\_i0\binding_parent_child_key

The most important factor at here is that you have a NodeId and a ParentNodeId. The sample has a FolderID and a ParentFolderID field.

The following topic explained the sample in greater detail:

http://doc.essentialobjects.com/library/1/menucommon/databinding/populate_parent_child_key.aspx

Please feel free to let us know if you have any more questions.

Thanks!
Kjell Ek
Posted: Tuesday, April 14, 2009 5:37:44 PM
Rank: Advanced Member
Groups: Member

Joined: 4/14/2009
Posts: 33
Using the examples
Unfortunately, I do not work. No error messages, but no menu appears .......

No sample files to look at?
eo_support
Posted: Tuesday, April 14, 2009 5:47:14 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
kjelle wrote:
No sample files to look at?


Do you mean the sample source code? The full sample source code is in your own machine. Just go to Start -> EO.Web Controls 2008 to find the sample short cut and load the whole sample project with Visual Studio and you will see how it works.
Kjell Ek
Posted: Wednesday, April 15, 2009 1:50:10 AM
Rank: Advanced Member
Groups: Member

Joined: 4/14/2009
Posts: 33
I mean sample source code with sql server dataset. The source code i found in not populated from a SQL database (SQL Dataset Binding). Exemlet shows only programmatic Creation.
eo_support
Posted: Wednesday, April 15, 2009 7:59:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The code will be something like this:

Code: Visual Basic.NET
'Define a DataSet. This part is the same as th sample code
Dim ds As New DataSet()
         
'Create the DataTable object. You can change the Table
'name here so that it matches your db
Dim table As DataTable = ds.Tables.Add("Folders")

'The following code is different than the sample. Unlike the sample
'that creates a DataTable by code, the following code loads the data
'from your DB by:
'1. Create a new SqlCommand object
'2. Execute the command and get a SqlDataReader object;
'3. Fill the DataTable with the SqlDataReader object;
Dim cmd As New SqlCommand(SelectCommand, MyConnection)
Dim reader As SqlDataReader = cmd.ExecuteReader()
table.Load(reader)

'The following code is different than the sample. The sample creates
'two new columns because it creates the DataTable object completely
'from code. Here we get the data column from the DataTable because
'the columns are defined by your SQL SELECT statement
Dim nodeIdColumn As DataColumn = table.Columns("nodeId")
Dim parentNodeIdColumn As DataColumn = table.Columns("ParentFolderID")

'This part is the same as the sample
Dim r As DataRelation = ds.Relations.Add(nodeIdColumn, parentNodeIdColumn)
r.Nested = True


Hope this helps.

Thanks!
Kjell Ek
Posted: Friday, April 17, 2009 5:09:12 PM
Rank: Advanced Member
Groups: Member

Joined: 4/14/2009
Posts: 33
Thanks for the help, now it works.
Only 2 questions kar before I turn on the big and buy the component.
How do I dynamically load from the database NavigateUrl and target in code behind?
Tested indicate binding.DataField = "NavigateUrl" but lost the menu title. Can not figure out how I enter the menu button title, NavigateUrl and target from my database?
Sorry my bad english....
eo_support
Posted: Friday, April 17, 2009 5:33:34 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You need to create multiple DataBinding objects. The code you see in the sample created a DataBinding object, then use it to map it CityWebSite to NavigateUrl, once the mapping is set, it calls Menu1.Bindings.Add to add the binding. If you want to map another field to another property (for example, "NodeTitle" field to menu item text), you would repeat the code to create another DataBinding object, set its properties and then call Add again to add this second binding. If you want a third one, create a third DataBinding object, etc.

You can also create DataBinding object via Menu Builder. That way you do not need to do it in code, so it is usually easier. This topic contains a screenshot about how to create DataBinding object via Menu Builder:

http://doc.essentialobjects.com/library/1/menucommon/databinding/populate_table.aspx

Hope this helps.

Thanks!
Kjell Ek
Posted: Sunday, April 19, 2009 9:40:55 AM
Rank: Advanced Member
Groups: Member

Joined: 4/14/2009
Posts: 33
Thanks for that, I think beginning to understand how the menu works now.
I have a node called Trash with NodeId 1. I want to set NodeId 1 to visible = False in the Code behind.
How do I do that in EO.Web Controls Menu?

In my old menu i set: Menu1.FindItemById("1").Visible = False

My code looks like this now ....
Code: Visual Basic.NET
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MyConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("MyTestConn"))

        Dim mainDs As DataSet = CreateDataSet()

        Menu1.DataSource = mainDs

        Menu1.DataFields = "sidnamn"

        Dim BindingUrl As New EO.Web.DataBinding()
        BindingUrl.Property = "NavigateUrl"
        BindingUrl.DataField = "NavigateUrl"
        Menu1.Bindings.Add(BindingUrl)

        Dim BindingTarget As New EO.Web.DataBinding()
        BindingTarget.Property = "TargetWindow"
        BindingTarget.DataField = "target"
        Menu1.Bindings.Add(BindingTarget)

        Menu1.TargetFrame = "home"

        Menu1.DataBind()

    End Sub

    Private Function CreateDataSet() As DataSet

        Dim SelectCommand As String = "SELECT NodeId, ParentNodeId, sidnamn, LookId, RightIcon, NavigateUrl, target from drag_sidor Order By NodeId ASC"
        MyDataAdapter = New SqlDataAdapter(SelectCommand, MyConnection)
        MyConnection.Open()
        Dim ds As New DataSet()

        Dim table As DataTable = ds.Tables.Add("drag_sidor")

        Dim cmd As New SqlCommand(SelectCommand, MyConnection)
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        table.Load(reader)

        Dim nodeIdColumn As DataColumn = table.Columns("nodeId")
        Dim parentNodeIdColumn As DataColumn = table.Columns("ParentNodeId")
        Dim r As DataRelation = ds.Relations.Add(nodeIdColumn, parentNodeIdColumn)

        r.Nested = True

        Return ds
    End Function
eo_support
Posted: Sunday, April 19, 2009 11:15:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You will need to do two things:

1. Make sure you map your nodeId to a MenuItem property. Otherwise because MenuItem does not contain any nodeId information, there is nothing to search upon. This means you need another DataBinding object. MenuItem provides two properties for you to store your own data: ItemID and Value. You can map your NodeID into either field;

2. Once you finished step 1, you would call this function to find the menu item with the matching ID:

http://doc.essentialobjects.com/library/1/eo.web.basenavigator.searchitems_overload_2.aspx
http://doc.essentialobjects.com/library/1/eo.web.basenavigator.searchitems_overload_1.aspx

You can use either version. The first version searches ItemID, the second version allows you to search Value.

Keep in mind that:

1. The function returns an array, not a single menu item. So you will need check whether the array is an empty array first. If it is not empty, then take the first element of the array;
2. The element of each array is a NavigationItem object. NavigationItem is the base class for MenuItem. So if you wish to access properties that are on MenuItem only, you will need to cast the NavigationItem object into MenuItem object first (use CType). In your case since you are only concerned about Visible property, so you do not need cast;

Hope this helps.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.