Hi
I am trying to bind WHDG to a dataset via code-behind and manual band and column definition.
Everything works fine if I assign and databind once.
However, sometimes I need to bind, then clear and then again bind to a different dataset.
In this case, the rows do not appear and rows.count keeps returning -1.
Have tried various options for clearing the original datasource and it appears that data is indeed cleared.
Pl advise ASAP
Thanks
Hello abhisinghal21,
Thank you for posting in the community.
I am currently looking into this issue for you. In order to investigate this further I will need an isolated, ready-to-run sample of your application where the issue is reproducible.
This is going to be highly appreciated and would be helpful in finding the root cause of this issue.
Please do not hesitate to contact me if you need any further assistance.
Pl find attached a very simple solution.
In the code-behind, if we bind it once, the grid displays correctly.
If we bind it twice, the grid shows blank and Rows.count returns -1.
Hi Vasya
Have tested the code you have sent and yes it works in the original situation.
Now I am trying it little differently - need to bind it to a dataset and apply relations after databinding.
The parent-child relationship does not appear if I do this and if I now try to cleardatasource and reassign any hierarchical dataset, it still does not appear.
Pl advise
Abhishek
Thank you for getting back to me.
I investgated you requirement further and what I can suggest is DataBinding grid after adding the relation. In this scenario the grid will be bound and rendered with the second data source with the newly added relation. For example:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then Me.WebHierarchicalDataGrid1.DataSource = TestClass.Dataset1 Dim ds As New DataSet() ds = WebHierarchicalDataGrid1.DataSource Dim relation As New DataRelation("IDRelation", ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ID")) ds.Relations.Add(relation) Me.WebHierarchicalDataGrid1.GridView.ClearDataSource() Me.WebHierarchicalDataGrid1.DataSource = ds Me.WebHierarchicalDataGrid1.GridView.DataBind() End If
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.WebHierarchicalDataGrid1.DataSource = TestClass.Dataset1
Dim ds As New DataSet()
ds = WebHierarchicalDataGrid1.DataSource
Dim relation As New DataRelation("IDRelation", ds.Tables(0).Columns("ID"), ds.Tables(1).Columns("ID"))
ds.Relations.Add(relation)
Me.WebHierarchicalDataGrid1.GridView.ClearDataSource()
Me.WebHierarchicalDataGrid1.DataSource = ds
Me.WebHierarchicalDataGrid1.GridView.DataBind()
End If
I am attaching to modified sample for your reference.
Please let me know if you have any further questions regarding this matter
Thanks Vasya - Understood this point.
Next question:
I am manually creating bands and columns (autogenerate=false)
Hence, before assigning a new datasource, I intend to call as follows:
oUltra.GridView.Band.Bands.Clear() oUltra.Rows.Clear() oUltra.GridView.Columns.Clear() oUltra.ClearTemplates() oUltra.GridView.ClearDataSource()
However, if I include the Band.Bands.Clear or oultra.bands.clear, a sys.argumentexception is thrown on client side javascript.
If I dont include the band.bands.clear call, the band.bands.count returns 1 even after cleardatasource.
Could you please modify my sample project attached in my previous response to this thread in order to make this issue reproducible?
This is going to be highly appreciated and would help me investigate this matter further.
Thank you for your cooperation on this matter.
Please let me know if you have any additional questions.
Hello Even Chen,
Please let me know if you need any further assistance with this matter.