Hello and thanks for your time:
I'm working with the WebHierarchicalDataGrid with a mix of bounddatafields and a templatedatafield that includes a button. The functionality I'm aiming for is for the user to be able to click the button and having the event fire which will then make changes to the database from which the grid is bound, then have the grid reflect these changes that the button caused. I currently have the events and the database changes working, the issue I've come across is the Grid is not reflecting the changes made from the button event.
I wrote up an example and in this there are a list of ID's, a bool, and the button that should set the bool to false in the database, only true entries should be shown in the grid. Clicking the button does indeed update the database, but the entry still exists on the Grid till you cause it to rebind with a sort or page change.
<div id="divMembers" runat="server"> <x2Vol:Members ID="x2vMembers" runat="server" /> <igwhdg:WebHierarchicalDataGrid ID="whdgTest" runat="server" StyleSetName="Claymation" EnableAjax="true" DataKeyFields="VolunteerID" DefaultColumnWidth="" Width="98%" Key="TestGrid" OnInitializeRow="whdgTest_InitializeRow" AutoGenerateBands=false AutoGenerateColumns=false > <Behaviors> <igwhdg:Sorting SortingMode=Single Enabled=true> </igwhdg:Sorting> </Behaviors> <Columns> <igwhdg:BoundDataField Key="volID" DataFieldName="VolunteerID"> <Header Text="VolID" /> </igwhdg:BoundDataField> <igwhdg:BoundDataField Key="IsApproved" DataFieldName="IsApproved"> <Header Text="Bool" /> </igwhdg:BoundDataField> <igwhdg:TemplateDataField Key="button" > <Header Text="Button" /> <ItemTemplate> <asp:Button ID="buttonClicker" runat="server" /> </ItemTemplate> </igwhdg:TemplateDataField> </Columns> </igwhdg:WebHierarchicalDataGrid></div>
Code Behind:
protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); Infragistics.Web.UI.DataSourceControls.DataView volView = new Infragistics.Web.UI.DataSourceControls.DataView(); VolunteerOrgCollection volColl = new VolunteerOrgCollection(); volColl.LoadAll(); volColl.Filter = "IsApproved = 1"; WebHierarchicalDataSource thisWHDS = new WebHierarchicalDataSource(); volView.DataSource = volColl; volView.ID = "volView"; thisWHDS.DataViews.Add(volView); whdgTest.DataSource = thisWHDS; whdgTest.DataMember = volView.ID; whdgTest.DataBind(); whdgTest.GridView.ItemCommand += new ItemCommandEventHandler(whdgTest_ItemCommand); } protected void whdgTest_ItemCommand(object sender, HandleCommandEventArgs e) { if (e.CommandName == "Clicker") { VolunteerOrg thisEntry = new VolunteerOrg(); thisEntry.LoadByPrimaryKey(int.Parse(e.CommandArgument.ToString())); thisEntry.IsApproved = false; thisEntry.Save(); Page_Load(null, null); } } protected void whdgTest_InitializeRow(object sender, RowEventArgs e) { WebHierarchyData whdVol = (WebHierarchyData)e.Row.DataItem; VolunteerOrg thisVolO = (VolunteerOrg)whdVol.Item; Button buttonClicker = (Button)e.Row.Items[whdgTest.Columns["button"].Index].FindControl("buttonClicker"); buttonClicker.CommandName = "Clicker"; buttonClicker.CommandArgument = thisVolO.MemberID.Value.ToString(); }
It feels as if the Grid is one step behind and this is causing issues when the user then clicks another cell's button, it ends up *not* being the cell they clicked on but another row's instead as it appears the data is correct behind the grid, but the actual display is not updated.
Is there a way for the grid to be forced to redisplay? Or a better way to handle events to prevent this?
Hi,
I am convinced that the template fields have not been worked out all the way in the WHDG. The events are not exposed, you can't edit templates from the smarttag, and I've seen my controls in a template column just not show up in parent bands.
It would be reassuring if one of the big guys would comment on this issue.
Ed
I believe I've solved the lag between the display and the data set. I scoured over the WebDataGrid and tried the suggested Grid.Rows.Clear() and then rebound my datasource, that solved that issue.
I came across a new one though: On the InitializeRowEvent I check the DataItem for the RowEventArgs and expect it to be a WebHiearchyData type, but instead of It got a DataRecord type after interacting with the grid.
I expected: Infragistics.Web.Ui.DataSourceControls.WebHierarchyData
instead I got: Infragistics.Web.Ui.Framework.Data.DataRecord
And this threw an error due to being an invalid cast. I checked the documentation and API to see if they were somehow related or if one inherited from the other but I don't believe so. I can catch the type and attempt to work around, but the DataRecord's dataitem is null.
Is there a work around to still access my row's dataitem, despite getting a datarecord?
Thanks,
Pearson
Edit: On a second pass it turns out the 2nd row I attempt to expand after using the link button will cause all the data to become the DataRecord type and the grid will just hang.
I'm trying to use a button in WHDG similar to the example you gave at the beginning of this thread, but I am unable to get the ItemCommand method to be invoked when I click on the button.
A postback occurs when I click the button, but nothing from the ItemCommand method. I can get the ActiveCellChanged event to fire...
Any assistance would be greatly appreciated! :)
Charles