Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
WHDG TemplateDataField buttons and affecting the dataset
posted

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?

 

 

Parents Reply Children
No Data