iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I have searched the tutorials/samples/forum for a way to bind a custom strongly typed class to a hierarchial WebGrid. In previous examples, I have used the WebGrid's OnInitializeDataSource event to retrieve a custom strongly typed object/class via a web service and bound to the WebGrid's DataSource property.
However, I am having problems using the hierarchal features of the WebGrid. The custom class has is flat and contains both header/child data and a relationship can be formed by various "ID" fields within the object. For example, consider the following data within the TransactionList object (List<TransactionList> data)
TransactionHeaderID TransactionHeaderName TransactionQueueID TransactionQueueName
1 Header 1 1 Queue 1
1 Header 1 2 Queue 2
2 Header 2 3 Queue 3
Is there a way using this data to have Header 1 with Queue 1/2 and Header 2 with Queue 3?
Hi Shawn,
First of all, forgive me. However, hierarchical data display is not meant to display from a flat data table. Because with hierarchical data display, It will renders the hierarchical elements and automatically load the other data source from the secondary table/ child table when needed. So in this case, unfortunately, if you are willing to use hierarchical from a flat data, I do not think we can do that.
However, we do have a grouping feature in flat data display to group the data based on a particular column(s). I hope it helps. Thank you and have a nice day.
Best Regards,
Andi Santoso
Can you provide an example of how to use this grouping feature?
Also, can you provide an example of how to use the hierarchical WebGrid using a strongly typed object? I did find an example using a DataSet but we don't bind to DataSets or any non-strongly typed objects.
Actually we do have a documentation on how to use the hierarchical WebGrid using a strongly typed object. You can go to "ms-help://ISNet.WebUI.WebGrid.V7/ISNet.WebUI.WebGrid/Outbound Mode.html" at our WebGrid's documentation.
To use grouping features, you can check them on our WebGrid sample named Grouping.aspx. It will show you on how to do a grouping in our WebGrid.
I hope it helps. Thank you and have a nice day.
Hi Shawn, Actually we do have a documentation on how to use the hierarchical WebGrid using a strongly typed object. You can go to "ms-help://ISNet.WebUI.WebGrid.V7/ISNet.WebUI.WebGrid/Outbound Mode.html" at our WebGrid's documentation. To use grouping features, you can check them on our WebGrid sample named Grouping.aspx. It will show you on how to do a grouping in our WebGrid. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso
Thank you for your response. I have spent a lot of time on this and haven't had any luck. Grouping will not work because I really need to show the relationship between parent/child (think of customer/order relationship).
Basically, I have a List<Customer> (custom object) and a List<Order> (custom object) and a simple ID field (property) is the relationship within the two. Can you please give me a sample of how to do that? Even the most simplistic example will help. I have a WCF web method that can populate these objects but I can't seem to figure out how to get the WebGrid to show the relationship in hierarchical view.
Thank you.
Attached is a sample on how to create a hierarchical WebGrid using Linq. I am using Northwind.dbml as a data. After that, I am also using the outbound mode to create the link between those two table. I hope it can helps your scenario. Thank you and have a nice day.
P.s: Put the .dbml file in your app_code.
Thanks for the fast reply. Unfortunately, this doesn't help me. The application's UI has no access to the database as we use a tiered application design. We use WCF to retrieve data from a SQL Server and populate custom objects that are then typically bound to the WebGrid's DataSource property via the WebGrid's OnInitializeDataSource event.
Can you provide an example of using custom strongly typed objects such as Sales/Orders? This would be extremely helpful.
Hi Shawn August,
If we do want to use Wcf Service, we do need to use a client-binding in our WebGrid to bind the data. So, we cannot bind them in OnInitializeDataSource event. Here is the link to our Wcf Service data source documentation, "ms-help://ISNet.WebUI.WebGrid.V7/ISNet.WebUI.WebGrid/Windows Communication Foundation (WCF) Service.html".
Also, we do have a running sample in our code sample. You can go to WebGrid samples and locate the ClientBinding_WcfService.aspx. I hope it helps. Thank you and have a nice day.
Hi Shawn August, If we do want to use Wcf Service, we do need to use a client-binding in our WebGrid to bind the data. So, we cannot bind them in OnInitializeDataSource event. Here is the link to our Wcf Service data source documentation, "ms-help://ISNet.WebUI.WebGrid.V7/ISNet.WebUI.WebGrid/Windows Communication Foundation (WCF) Service.html". Also, we do have a running sample in our code sample. You can go to WebGrid samples and locate the ClientBinding_WcfService.aspx. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso
It doesn't matter what populates these objects. Please forget I even said WCF. I am trying to bind to a custom object using the OnInitializeDataSource. For example, bind to a List<Customer> where each Custom class has an instance of List<Order>.
Or please let me know if there is another way. The most important is that it's custom strongly typed objects.
Forgive me, I think that I will need to have more time to investigate this scenario of yours. I will try my best to give you the solution on the next day. Sorry for the inconvenience. Thank you and have a nice day.
Hi Shawn, Forgive me, I think that I will need to have more time to investigate this scenario of yours. I will try my best to give you the solution on the next day. Sorry for the inconvenience. Thank you and have a nice day. Best Regards, Andi Santoso
Any update on this? I am surprised this seems to be a special request. Any solution where the UI interacts directly with the database violates n-tiered application design. Furthermore, using custom strongly typed objects is a very favorable design approach.
I really appreciate the help.
Forgive me for MIA, we had a couple days off last week. I think, I will do need more time to investigate this scenario. I have also forwarded this to our Developer team.
Thank you for being patience. I hope it helps and I will inform you as soon as I get a news from them.
Hi Shawn, Forgive me for MIA, we had a couple days off last week. I think, I will do need more time to investigate this scenario. I have also forwarded this to our Developer team. Thank you for being patience. I hope it helps and I will inform you as soon as I get a news from them. Best Regards, Andi Santoso
Can I get an update?
Sorry for the delay. There is some small problem to do this scenario with the our WebGrid. However, it has been fixed. Please ensure to put the .cs files in you App_Code.Please donwload the dll here, and make sure you have upgraded the dll of WebGrid as well.
However, this is a nightly build version. so, disclaimer on: Any feedbacks will be highly appreciated if encountered any issue regarding this build.
disclaimer on: Any feedbacks will be highly appreciated if encountered any issue regarding this build. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso
disclaimer on: Any feedbacks will be highly appreciated if encountered any issue regarding this build.
I'm testing now. We are using WebGrid.dll version 7.0.7200.306 but this new version is 7.0.7200.403. Is the fix referred to above the only change?
Not really, there are more than that. If you go to http://support.intersoftpt.com, you will see there are lot of enhancement being made in there.
Thank you and have a nice day.
Hi Shawn, Not really, there are more than that. If you go to http://support.intersoftpt.com, you will see there are lot of enhancement being made in there. Thank you and have a nice day.Best Regards,Andi Santoso
I made some progress. However, I still can't seem to figure out how to control the output. It seems like the WebGrid's RetrieveHierarchicalStructure method is the only way to get the WebGrid to display hierarchical data even though I am specifying the template on the ASPX side. I need to be able to control the UI of the parent/child fields. For example, here's the current ASPX for the parent. I need to be able to do the same for the child. However, it seems like the RetrieveHierarchicalStructure property overrides this. Please help.
<RootTable Caption="Transactions"> <Columns> <ISWebGrid:WebGridColumn Caption="" DataMember="TransactionHeaderID" DataType="System.String" EditType="NoEdit" Name="TransactionHeaderID" Width="0px" Visible="false" /> <ISWebGrid:WebGridColumn Caption=" " Name="TreatyProcessButton" DataMember="" HiddenDataMember="TransactionHeaderID" DataType="System.String" Width="65px" ButtonText="Treaty Process" ColumnType="Template" EditType="NoEdit" NewRowEditType="NoEdit" Bound="true"> <ButtonStyle BackColor="AliceBlue"> <Padding Top="2px" Left="1px" Right="1px" Bottom="1px" /> </ButtonStyle> <CellTemplate> <img runat="server" id="imgTreatyProcess" name="imgTreatyProcess" src="~/Images/Buttons/process_off.gif" alt="Process the treaty" border="0" style="padding-top: 1px;" onclick="javascript:treatyProcess();" onmouseout="javascript:MM_swapImgRestore()" onmouseover="javascript:MM_swapImage(this.id,'','../../Images/Buttons/process_on.gif',1)" /> </CellTemplate> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="" FilterEditType="NoEdit" ColumnType="Image" EditType="NoEdit" Name="imgTreatyProcess" Width="20px" /> <ISWebGrid:WebGridColumn Caption="Status" DataMember="TransactionHeaderStatusID" FilterEditType="DropdownList" EditType="NoEdit" Name="TransactionHeaderStatusID" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Treaty" DataMember="TreatyID" FilterEditType="TextBox" DataType="System.String" EditType="NoEdit" Name="TreatyID" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Transaction" DataMember="TransactionTypeName" FilterEditType="DropdownList" DataType="System.String" EditType="NoEdit" Name="TransactionTypeName" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Transaction Description" DataMember="TransactionHeaderDescription" FilterEditType="TextBox" DataType="System.String" EditType="NoEdit" Name="TransactionHeaderDescription" Width="200px" /> <ISWebGrid:WebGridColumn Caption="Assigned To" DataMember="AssignedTo" FilterEditType="TextBox" DataType="System.String" EditType="NoEdit" Name="AssignedTo" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Assigned On" DataMember="AssignedOn" FilterEditType="CalendarCombo" DataType="System.DateTime" EditType="NoEdit" Name="AssignedOn" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Created By" DataMember="CreatedBy" FilterEditType="TextBox" DataType="System.String" EditType="NoEdit" Name="CreatedBy" Width="100px" /> <ISWebGrid:WebGridColumn Caption="Created On" DataMember="CreatedOn" FilterEditType="CalendarCombo" DataType="System.DateTime" EditType="NoEdit" Name="CreatedOn" Width="100px" /> </Columns> </RootTable>
Yes, when you use RetrieveHierachicalStructure, it will overrides all of them. You could simply remove the RetrieveHierachicalStructure from your code. If it is still not working, could you send a running simple sample for me to investigate it furtermore?
Hi Shawn, Yes, when you use RetrieveHierachicalStructure, it will overrides all of them. You could simply remove the RetrieveHierachicalStructure from your code. If it is still not working, could you send a running simple sample for me to investigate it furtermore? Thank you and have a nice day.Best Regards,Andi Santoso
Yes, I removed that line of code and no hierarchy exists. That's probably because I am not specifying a "ChildTable" on the ASPX. Can you modify that existing code you provided above to use the ASPX to display parent/child fields in hierarchy? I can use that for my example.
If you do not define the child table, during PrepareDataBinding WebGrid event handler you will need to create the child table and child table column structure and reset the hierarchical property under LayoutSettings.
Here is the snippet for the PrepareDataBinding event for the sent sample with your scenario applied:
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e){ if(!Page.IsPostBack) { WebGrid1.RootTable.ChildTables.Add("Order"); WebGridTable orderTbl = WebGrid1.RootTable.ChildTables[0]; orderTbl.DataMember = "Order"; orderTbl.Columns.AddRange(new WebGridColumn[] { new WebGridColumn("OrderID","OrderID","OrderID"), new WebGridColumn("CustomerID","CustomerID","CustomerID"), new WebGridColumn("OrderName","OrderName","Name"), new WebGridColumn("OrderQuantity","OrderQuantity","Quantity"), }); } WebGrid1.LayoutSettings.Hierarchical = true;}
The WebGrid RootTable definition:
<RootTable DataMember="Customer" DataKeyField="CustomerID"> <Columns> <ISWebGrid:WebGridColumn DataMember="CustomerID" Name="ID"></ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn DataMember="CustomerName" Name="Name"></ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn DataMember="CustomerAddress" Name="Address"></ISWebGrid:WebGridColumn> </Columns></RootTable>
.
I specified the DataMember and the DataKeyField for both the root and child table and it still doesn't render.
Can you modify the above example accordingly so I can see waht I am missing?!
I cannot modify your sample since I do not know which one is the child table. To make it easier for me to investigate, could you provide me with the sample and possibly your database?
However, please ensure that you have specified the child table in prepare data binding server side.
Hi Shawn, I cannot modify your sample since I do not know which one is the child table. To make it easier for me to investigate, could you provide me with the sample and possibly your database? However, please ensure that you have specified the child table in prepare data binding server side. Thank you and have a nice day.Best Regards,Andi Santoso
The sample was provided by Andi Santose on the April 12, 2010 @ 4:05AM post.
However, I added the code above via server-side's PrepareBinding and it finally worked. Does that mean I am forced to define the structure via server-side? I assume anything I can do via ASPX I can do via server-side. It would be nice to have the flexibility if possible.
If we are willing for not using RetrieveHierarchicalStructure, then we will need to specify all the parent and child row in the HTML code. From what I see on your provided code, I did not see that you have specified that in particular. If we do so, we do not need to use RetrieveHierarchicalStructureMethod.
Attached is a simple sample that I created under Hierarchical WebGrid. Notice that I do not call RetireveHierarchicalMethod in the server. However, the structure is still persisted.
Hi Shawn, If we are willing for not using RetrieveHierarchicalStructure, then we will need to specify all the parent and child row in the HTML code. From what I see on your provided code, I did not see that you have specified that in particular. If we do so, we do not need to use RetrieveHierarchicalStructureMethod. Attached is a simple sample that I created under Hierarchical WebGrid. Notice that I do not call RetireveHierarchicalMethod in the server. However, the structure is still persisted. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso That doesn't work with strongly typed custom objects with the new DLL .403 that is discussed within this thread.Hi Shawn, If we are willing for not using RetrieveHierarchicalStructure, then we will need to specify all the parent and child row in the HTML code. From what I see on your provided code, I did not see that you have specified that in particular. If we do so, we do not need to use RetrieveHierarchicalStructureMethod. Attached is a simple sample that I created under Hierarchical WebGrid. Notice that I do not call RetireveHierarchicalMethod in the server. However, the structure is still persisted. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso That doesn't work with strongly typed custom objects with the new DLL .403 that is discussed within this thread. Hi Shawn, If we are willing for not using RetrieveHierarchicalStructure, then we will need to specify all the parent and child row in the HTML code. From what I see on your provided code, I did not see that you have specified that in particular. If we do so, we do not need to use RetrieveHierarchicalStructureMethod. Attached is a simple sample that I created under Hierarchical WebGrid. Notice that I do not call RetireveHierarchicalMethod in the server. However, the structure is still persisted. I hope it helps. Thank you and have a nice day. Best Regards, Andi Santoso
Hi Shawn, If we are willing for not using RetrieveHierarchicalStructure, then we will need to specify all the parent and child row in the HTML code. From what I see on your provided code, I did not see that you have specified that in particular. If we do so, we do not need to use RetrieveHierarchicalStructureMethod. Attached is a simple sample that I created under Hierarchical WebGrid. Notice that I do not call RetireveHierarchicalMethod in the server. However, the structure is still persisted. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso That doesn't work with strongly typed custom objects with the new DLL .403 that is discussed within this thread.
That doesn't work with strongly typed custom objects with the new DLL .403 that is discussed within this thread.
That doesn't work with strongly typed custom objects with the new DLL .403 that is discussed within this thread. But, if I specify the structure via code-behind, it does work.
Yes, for the particular sample that I have created for you, this cannot be done since we have created the WebGrid programmaticly and bind them thru PreInitialize. So, I will suggest you to use specify the structure via code-behind. And define the structure in PrepareDataBinding server side event.
Hi Shawn, Yes, for the particular sample that I have created for you, this cannot be done since we have created the WebGrid programmaticly and bind them thru PreInitialize. So, I will suggest you to use specify the structure via code-behind. And define the structure in PrepareDataBinding server side event. Thank you and have a nice day.Best Regards,Andi Santoso
OK.
I ran into another problem using a Hierarchical Grid's WebValueList. The following exception occurs when the WebValueList's DataSource property is set: IHierarchicalList.ItemType should not be null!
I have added the method below that is widely used in my application but does not work with the Hierarcical Grid.
/// <summary> /// Creates a WebValueLooup for the specified column. /// </summary> /// <param name="nvList"></param> /// <param name="columnName"></param> public static void CreateWebValueLookup(WebGrid grid, object datasource, string columnName) { WebValueList wvList = grid.RootTable.Columns.GetNamedItem(columnName).ValueList; wvList.DataSource = datasource; wvList.DataMember = ""; wvList.DataTextField = CommonConstants.COL_NAME_VALUE_VALUE; wvList.DataValueField = CommonConstants.COL_NAME_VALUE_ID; }
I have created a simple running sample using dsNorthwind database. In that sample, I have created a WebValueList under a Hierarchical WebGrid and I used a RootTable to attach my WebValue. However, if you are willing to attach the WebValue in the Child table, instead of grid.RootTable, you can simply use grid.GetTableByName("TableName").
Please kindly try and run my sample in your end and see if this meets your scenario. However, I do not find any issue in this. If it does not meet your scenario, could you kindly modify my sample so that, it will replicate the issue of yours and send me back for further investigation.
Hi Shawn, I have created a simple running sample using dsNorthwind database. In that sample, I have created a WebValueList under a Hierarchical WebGrid and I used a RootTable to attach my WebValue. However, if you are willing to attach the WebValue in the Child table, instead of grid.RootTable, you can simply use grid.GetTableByName("TableName"). Please kindly try and run my sample in your end and see if this meets your scenario. However, I do not find any issue in this. If it does not meet your scenario, could you kindly modify my sample so that, it will replicate the issue of yours and send me back for further investigation. Thank you.Best Regards,Andi Santoso
I modified your example to reproduce the issue. The code in your example to define the WebValueList is very similiar to the one I posted above. This has worked without problems in the past but does not with the new DLLs, using strongly typed objects as a datasource, and using a hierarchical grid as discussed within this thread.
Hi Swan,
After I discuss this with our Developer, it seems that since we are using unBound WebGrid, we cannot using WebValue List. WebValue List should be used in WebGrid with bound data source, if not, it's simply conflicting with the nature of the databinding concept. I hope it helps. Thank you.
Hi Swan, After I discuss this with our Developer, it seems that since we are using unBound WebGrid, we cannot using WebValue List. WebValue List should be used in WebGrid with bound data source, if not, it's simply conflicting with the nature of the databinding concept. I hope it helps. Thank you.Best Regards,Andi Santoso
Is there any work-around? If not, then WebValueList is not possible, at all, using strongly typed classes for a hierarical grid.
I did verify my code works after I removed the creating of the hierarchy structure within the code-behind (which is necessary for me).
Unfortunately, using WebValue List, the WebGrid itself has to be bound to DataSource, since on declaring the WebValue List we used DataValueField to connect to the WebGrid itself. So like I mentioned before, using unBound grid and WebValue List is simply conflicting with the nature of the databinding concept. So it is not meant to be used that way.
Hi Shawn, Unfortunately, using WebValue List, the WebGrid itself has to be bound to DataSource, since on declaring the WebValue List we used DataValueField to connect to the WebGrid itself. So like I mentioned before, using unBound grid and WebValue List is simply conflicting with the nature of the databinding concept. So it is not meant to be used that way. I hope it helps. Thank you and have a nice day. Best Regards, Andi Santoso
I found a weird issue that I can only duplicate with this grid where the WebGrid's OnInitializeDataSource event goes off twice whenever the grid is refreshed from the client-side. Can you confirm? If not, what else would cause this event to go off twice?
OnInitializeDataSource event goes off twice whenever the grid is refreshed from the client-side. Can you confirm? If not, what else would cause this event to go off twice?
Please ensure that you have add the "Global.asax" file in your root project. If we do not define the file, the ASP.NET page framwork assumes that we have not defined any application or session event handlers. You can right click on your root project, create a new file of Global.asax and just leave it blank.
In new Visual Studio 2010, I believe that, this file, "Global.asax" will be automatically included everytime we have created a new project.
Andi Santoso.
Hi Shawn, Please ensure that you have add the "Global.asax" file in your root project. If we do not define the file, the ASP.NET page framwork assumes that we have not defined any application or session event handlers. You can right click on your root project, create a new file of Global.asax and just leave it blank. In new Visual Studio 2010, I believe that, this file, "Global.asax" will be automatically included everytime we have created a new project. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso.
That file does exist and is widely used for global error handling. I am not sure how this will cause the WebGrid's OnInitializeDataSource event to fire twice when the client-side WebGrid's refresh method is called?
It is weird then, I am having a problem to replicate the issue of yours. At first try, it is true that the OnInitializeDataSource is being called twice when I refreshed the grid from client side. However, when I added "Global.asax" file in my project, the OnInitializeDataSource is only being called once.
Is it possible to provide me with your Global.asax for me to investigate them? Or perhaps, you can try to create a new project with only one file in it. Summon WebGrid and try to do the exact scenario with an empty Global.asax in your project, see if that event is being called twice or once.
Hi Shawn, It is weird then, I am having a problem to replicate the issue of yours. At first try, it is true that the OnInitializeDataSource is being called twice when I refreshed the grid from client side. However, when I added "Global.asax" file in my project, the OnInitializeDataSource is only being called once. Is it possible to provide me with your Global.asax for me to investigate them? Or perhaps, you can try to create a new project with only one file in it. Summon WebGrid and try to do the exact scenario with an empty Global.asax in your project, see if that event is being called twice or once. Thank you and have a nice day. Best Regards, Andi Santoso
Nice find! I re-added the Global.asax file and it stopped firing twice. *REALLY* odd. If you re-remove it, does it happen again for you? I wonder what is causing this.
If we do not include Global.asax, the session is not enabled automatically. That is why the InitializeDataSource is being called twice. I hope it helps. Thank you and have a nice day.
Hi Shawn, If we do not include Global.asax, the session is not enabled automatically. That is why the InitializeDataSource is being called twice. I hope it helps. Thank you and have a nice day.Best Regards,Andi Santoso
This makes sense but my application already had a Global.asax that was working properly. Oddly, I removed/re-added it and the event is firing only once. Not sure why but it's fixed.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname