Hello. Due to the relative complexities of the application I am trying to build, I am going to need to do all of my data binding of the WebHierarchicalDataGrid dynamically. This is my first time using infragistics and I am finding that to do anything not with the quickmenu or with markup gets a bit finnicky.
I have spent lots of time trying to find out what is going wrong here, but i simply cannot find anything... Here is the relevant code I am using so far:
protected void Page_Load(object sender, EventArgs e)
{
_Grid.RowIslandsPopulating += new ContainerRowCancelEventHandler(_Grid_RowIslandsPopulating);
_Grid.InitializeRow += new InitializeRowEventHandler(_Grid_InitializeRow);
_Grid.PreRender += new EventHandler(_Grid_PreRender);
LoadGrid();
}
void _Grid_PreRender(object sender, EventArgs e)
if (!(IsPostBack))
foreach (ContainerGridRecord row in _Grid.GridView.Rows)
row.IsEmptyParent = true;
void _Grid_InitializeRow(object sender, RowEventArgs e)
((ContainerGridRecord)e.Row).IsEmptyParent = true;
void _Grid_RowIslandsPopulating(object sender, ContainerRowCancelEventArgs e)
e.Cancel = true;
Int32 cscpID = (int)e.Row.DataKey[0];
SqlDataAdapter dA = new SqlDataAdapter(QueryCommand("cscpID:" + cscpID.ToString() + " view:WP"));
DataSet ds = new DataSet();
dA.Fill(ds, "CHILD");
ContainerGrid childGrid = new ContainerGrid();
e.Row.RowIslands.Add(childGrid);
childGrid.Key = "CHILD";
childGrid.Level = 1;
childGrid.DataKeyFields = "cscpID";
childGrid.DataSource = ds;
childGrid.DataBind();
void LoadGrid()
_Grid.InitialDataBindDepth = 0;
_Grid.AutoGenerateColumns = false;
_Grid.AutoGenerateBands = false;
_Grid.InitialExpandDepth = 0;
_Grid.Width = 1000;
_Grid.ExpandCollapseAnimation.SlideOpenDuration = 300;
_Grid.ExpandCollapseAnimation.SlideCloseDuration = 300;
InitRootBand(ref _Grid);
InitChildBand(ref _Grid);
InitDataViews(ref _Grid, ref _dataSource);
InitDataRelations(ref _Grid, ref _dataSource);
_Grid.DataMember = "PARENT";
_Grid.DataKeyFields = "id";
_Grid.DataSource = _dataSource;
_Grid.DataBind();
private void InitDataRelations(ref WebHierarchicalDataGrid grid, ref WebHierarchicalDataSource src)
Infragistics.Web.UI.DataSourceControls.DataRelation drMain = new Infragistics.Web.UI.DataSourceControls.DataRelation();
drMain.ParentDataViewID = "PARENT";
drMain.ChildDataViewID = "CHILD";
drMain.ParentColumns = new string[] { "id" };
drMain.ChildColumns = new string[] { "cscpID" };
src.DataRelations.Add(drMain);
private void InitDataViews(ref WebHierarchicalDataGrid grid, ref WebHierarchicalDataSource src)
Infragistics.Web.UI.DataSourceControls.DataView dvSCP = new Infragistics.Web.UI.DataSourceControls.DataView();
Infragistics.Web.UI.DataSourceControls.DataView dvWP = new Infragistics.Web.UI.DataSourceControls.DataView();
SqlDataAdapter dA = new SqlDataAdapter(QueryCommand("county:zavala"));
dA.Fill(ds, "PARENT");
dvSCP.ID = "PARENT";
dvSCP.DataSource = ds;
dvSCP.DataMember = "PARENT";
src.DataViews.Add(dvSCP);
SqlDataAdapter childdA = new SqlDataAdapter(QueryCommand("county:zavala view:wp"));
DataSet childds = new DataSet();
dA.Fill(childds, "CHILD");
dvWP.ID = "CHILD";
dvWP.DataSource = childds;
dvWP.DataMember = "CHILD";
src.DataViews.Add(dvWP);
private void InitRootBand(ref WebHierarchicalDataGrid grid)
grid.DataMember = "PARENT";
grid.DataKeyFields = "id";
grid.Columns.Add(newColumn("id", "ID", "id", null, false));
grid.Columns.Add(newColumn("State", "State", "p_State", null, false));
private void InitChildBand(ref WebHierarchicalDataGrid grid)
Band childBand = new Band();
grid.Bands.Add(childBand);
childBand.AutoGenerateColumns = false;
childBand.Key = "CHILD";
childBand.DataMember = "CHILD";
childBand.DataKeyFields = "cscpID";
childBand.Columns.Add(newColumn("ID", "ID", "ID", null, false));
childBand.Columns.Add(newColumn("cscpID", "cscpID", "cscpID", null, false));
childBand.Columns.Add(newColumn("State", "State", "c_State", null, false));
ASPX Code:
<form id="form1" runat="server">
<asp:ScriptManager ID="_scriptMan" runat="server">
</asp:ScriptManager>
<div>
<ig:WebHierarchicalDataGrid ID="_Grid" runat="server" >
</ig:WebHierarchicalDataGrid>
<ig:WebHierarchicalDataSource ID="_dataSource" runat="server">
</ig:WebHierarchicalDataSource>
</div>
</form>
The parent grid binds and loads successfully, and i see the data, but when I click on the arrow to expand a row, it gives me a popup error with a [NotSupportedException] and the message
"Key:id must be unique. The field objects in the grid must have non-empty unique keys assigned to the Key property"
please help!!! I don't know what i can do if i don't get this working...
in case you are wondering, the data is being pulled via stored procedure. the "id" field in both parent and child tables is definitely unique, and the cscpID field is a foreign key to "id" between the parent and child tables.
Hi all,
I was having the same problem as mflach. I resolved the problem by calling the grid.columns.clear() method prior to databinding.
Hope this helps.
Steve
Please take a look at the following discussion which provides details on configuring WHDG dynamically:
http://community.infragistics.com/forums/t/44916.aspx
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://es.infragistics.com/support
Any update on this? I may be having the same issue. I'm loading a WebHierarchicalDataSource dynamically and everything works fine until I execute a second postback. Then I get the same error you were getting.
hmm... I tried adding it wherever made sense... same issue occurred.
thanks for the help though! any other ideas?
in the beginning or at the end?