Hello togheter,
could somebody please support me by the following data binding issue:
On my web site I have two buttons (A & B).
When I click button A, I would like to bind data source A with the dedicated columns to the WebHierarchicalDataGrid.
When I click button B, I would like to bind data source B with the dedicated columns to the WebHierarchicalDataGrid.
HTML:
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="500px" Width="400px">
<GroupingSettings EnableColumnGrouping="True" GroupAreaVisibility="Visible" GroupByAreaLocation="Top"/>
<Behaviors>
<ig:Activation Enabled="true"></ig:Activation>
<ig:Selection Enabled="true" RowSelectType="Single" CellClickAction="Row" ></ig:Selection>
<ig:RowSelectors Enabled="true" RowNumbering="true" EnableInheritance="true"></ig:RowSelectors>
<ig:Paging Enabled="true" EnableInheritance="true" PagerMode="Numeric" PageSize="100"></ig:Paging>
<ig:Sorting Enabled="true" EnableInheritance="true" SortingMode="Single"></ig:Sorting>
</Behaviors>
</ig:WebHierarchicalDataGrid>
<asp:Button ID="Button_A" runat="server" Text="Button_A" OnClick="Button_A_Click" />
<asp:Button ID="Button_B" runat="server" Text="Button_B" OnClick="Button_B_Click" />
</div>
</form>
</body>
Page_Load:
if(!Page.IsPostBack)
{
Session["DataSource_Session"] = null;
WebHierarchicalDataGrid1.AutoGenerateColumns = false;
}
object data = Session["DataSource_Session"];
if(data != null)
if (data.GetType() == typeof(A[]))
WebHierarchicalDataGrid1.DataKeyFields = WebHierarchicalDataGrid1.Columns[0].Key;
WebHierarchicalDataGrid1.DataSource = (A[])data;
WebHierarchicalDataGrid1.DataBind();
else if (data.GetType() == typeof(B[]))
WebHierarchicalDataGrid1.DataSource = (B[])data;
Button_Click_Event:
protected void Button_B_Click(object sender, EventArgs e)
try
WebHierarchicalDataGrid1.Columns.Clear();
WebHierarchicalDataGrid1.GridView.ClearDataSource();
BoundDataField dtf = new BoundDataField();
dtf.Header.Text = "Unique ID";
dtf.Key = "uniqueID";
dtf.DataFieldName = "uniqueID";
BoundDataField dtf1 = new BoundDataField();
dtf1.Header.Text = "Value B";
dtf1.Key = "valueB";
dtf1.DataFieldName = "valueB";
WebHierarchicalDataGrid1.Columns.Add(dtf);
WebHierarchicalDataGrid1.Columns.Add(dtf1);
B[] valueList = new B[10];
for (int i = 0; i < 10; i++)
B obj = new B();
obj.uniqueID = i;
obj.valueB = "Value B " + i.ToString();
valueList[i] = obj;
WebHierarchicalDataGrid1.DataKeyFields = WebHierarchicalDataGrid1.Columns[0].Key WebHierarchicalDataGrid1.DataSource = valueList;
WebHierarchicalDataGrid1.GridView.DataKeyFields = WebHierarchicalDataGrid1.DataKeyFields;
WebHierarchicalDataGrid1.GridView.DataSource = WebHierarchicalDataGrid1.DataSource;
WebHierarchicalDataGrid1.GridView.DataBind();
WebHierarchicalDataGrid1.RefreshBehaviors();
Session["DataSource_Session"] = valueList;
catch (Exception ex)
string msg = ex.Message;
protected void Button_A_Click(object sender, EventArgs e)
dtf1.Header.Text = "Value A";
dtf1.Key = "valueA";
dtf1.DataFieldName = "valueA";
A[] valueList = new A[10];
A obj = new A();
obj.valueA = "Value A " + i.ToString();
Data_Source_Class:
public class A
Int64 _uniqueID;
public Int64 uniqueID
get { return _uniqueID; }
set { _uniqueID = value; }
string _valueA;
public string valueA
get { return _valueA; }
set { _valueA = value; }
public class B
string _valueB;
public string valueB
get { return _valueB; }
set { _valueB = value; }
Thanks in advanced.
Hello help123,
Thank you for posing in our community.
I made a small sample from the code snippets provided. I noticed that you are trying to set the data source for the WebHierarchialDataGrid multiple times. I removed the additional data bindings and on my side the sample was working as expected.
I am attaching the sample project for your reference. Please test this on your side and let me know whether it helps you achieve your requirement.
Please feel free to contact me if you have any additional questions regarding this matter.
Hello,
thank you for the fast support. Unfortunatelly it is not working properly on my site. The pageing, sorting and grouping doesn't work as expected.
I have a working solution with 'AutoGenerateColumns = true' (see below). All I need is to substitute the 'AutoGenerateColumns = true' with BoundDataField:
e.G.:
BoundDataField dtf = new BoundDataField(); dtf.Header.Text = "Unique ID"; dtf.Key = "uniqueID"; dtf.DataFieldName = "uniqueID"; BoundDataField dtf1 = new BoundDataField(); dtf1.Header.Text = "Value A"; dtf1.Key = "valueA"; dtf1.DataFieldName = "valueA";
BoundDataField dtf = new BoundDataField();dtf.Header.Text = "Unique ID";dtf.Key = "uniqueID";dtf.DataFieldName = "uniqueID";BoundDataField dtf1 = new BoundDataField();dtf1.Header.Text = "Value B";dtf1.Key = "valueB";dtf1.DataFieldName = "valueB";
Could you please show me how to solve the problem? P.S.: I am using Infragsitics V 14.1.
Here the working code.
if (!IsPostBack) { Session["DataSource_Session"] = null; WebHierarchicalDataGrid1.AutoGenerateColumns = true; } object data = Session["DataSource_Session"]; if (data != null) { if (data.GetType() == typeof(A[])) { WebHierarchicalDataGrid1.DataKeyFields = "uniqueID"; WebHierarchicalDataGrid1.DataSource = (A[])data; WebHierarchicalDataGrid1.DataBind(); } else if (data.GetType() == typeof(B[])) { WebHierarchicalDataGrid1.DataKeyFields = "uniqueID"; WebHierarchicalDataGrid1.DataSource = (B[])data; WebHierarchicalDataGrid1.DataBind(); } }
Button_Event:
protected void Button_A_Click(object sender, EventArgs e) { WebHierarchicalDataGrid1.GridView.ClearDataSource(); A[] valueList = new A[1000]; for (int i = 0; i < 1000; i++) { A obj = new A(); obj.uniqueID = i; obj.valueA = "Value A " + i.ToString(); valueList[i] = obj; } WebHierarchicalDataGrid1.DataKeyFields = "uniqueID"; WebHierarchicalDataGrid1.DataSource = valueList; WebHierarchicalDataGrid1.DataBind(); Session["DataSource_Session"] = valueList; }
protected void Button_B_Click(object sender, EventArgs e) { WebHierarchicalDataGrid1.GridView.ClearDataSource(); B[] valueList = new B[1000]; for (int i = 0; i < 1000; i++) { B obj = new B(); obj.uniqueID = i; obj.valueB = "Value B " + i.ToString(); valueList[i] = obj; } WebHierarchicalDataGrid1.DataKeyFields = "uniqueID"; WebHierarchicalDataGrid1.DataSource = valueList; WebHierarchicalDataGrid1.DataBind(); Session["DataSource_Session"] = valueList; }
Model and HTML:
No changes!
Thanks in advanced!
Hi, I have another 2 side effects which I could not solve:
- When I open the page in two browser tabs the function is not working properly
- In my main project some columns are hidden. When I open the page in two browser tabs in one all columns are displayed. I figured out that the <head> with ‘runat=server’ has some impact. But I could not finally solve the problem. What could be the reason?
I tested he provided sample and following the steps that you suggested I was unable to reproduce the issue with the hidden columns that you are describing. I added one hidden column in the grid and regardless of how many browser tabs I have opened with the application hidden columns remained hidden.
Regarding the first issue I assume that the function that you are mentioning is the function that changes the data source for the grid. On my side this was working as expected as well and the underlying data source of the grid was flawlessly changed upon a button click.
I modified the sample that I have provided to you in order to add an additional hidden column in the grid and I am attaching it for your reference. Please test this on your side and let me know whether you are experiencing mentioned issues with the sample. If not, please feel free to modify my sample and send it back to me.
If you are having the same issue with my sample as well could you please make a video illustrating the behavior on your side and provide me with steps to reproduce the issue and some additional information regarding the browser and browser version.
Looking forward to hearing from you.
Hi, please see attachment. The issue occurs on IE 11 as well as on Firefox. BR
Thank you for the provided video.
Since I am not able to reproduce this behavior on my side could you please modify the sample project that I provided in my last post in order to reproduce the issue.
This will help me debug on my side and investigate further in pursuit of the root cause of the issue.
Thank you for your cooperation on this matter.
Looking forward to hearing from you
Hi, please see attachment.
Hi..im new to infragistics controls ,im using webhierarchicaldatagrid in my project
how to bind data to infragistics webhierarchicaldatagrid through javascript, im having data in datatable ,
dtParent to bind data and dtchild to bind records to bands ..i.e onexpanding a row dtchild has to bind
I am glad that your issue is resolved.
Please let me know if you have any additional questions.
Hi, with the new version the behaviour is correct. Thanks and best regards
I noticed that in your sample project you are using the RTM build of version 14.1 - 14.1.20141.1015.
Could you please try downloading the latest service release available for NetAdvantage 14.1, which currently is 14.1.20141.2283. This could be achieved by following these steps:
1) Go to our web site www.infragistics.com and log with your account.
2) Click Support/Account in the top right corner of the page
3) You will see Welcome, [Your name] on the top of the menu that will appear. Click on the Welcome word.
4) This will lead you to My Keys&Downloads section. Select your product from the list
Under the Service Releases tab you will find the latest service release available for download.
Please test your sample with this service release and let me know whether you are still experiencing this issue.