I'm using the webdatagrid from version 2010 vol 3. The grid has filtering, sorting and paging enabled. When the page is postback, I always set the grid datasource from the Page_load with the data just in case any of the 3 features were used from the UI.
The problem with this is when the user select rows and hit a button, The WebDataGrid.Behaviors.Selection.SelectedRows.Count has the right count of selected rows, but all the row objects in the list are nulls. If I don't set the datasource in the page_load, they are not null. The problem is that if I don't set the datasource in the page load, the sorting, filtering and paging aren't working. I tried to set the datasource only in the "ed" events (filtered, sorted, etc.), but it's not working either.
For now, I'm thinking of copynig all selected rows in a temporary list to be able to access them later in the code. Any other ideas?
Any help would be greatly appreciated.
Hi yveslangevin,
In order to be able to provide some advice I would need some more information of the type of dataSource that you are using and the exact build that you are using. Sample code will be much appreciated.
Please contact me if you have any questions.
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://www.infragistics.com/support
Hi,
Sure, here's the code:
I have a datagrid within an updatepanel:
<asp:UpdatePanel ID="dataGridUpdPnl" runat="server" > <ContentTemplate> <ig:WebDataGrid ID="reportDataIGGrd" runat="server" AutoGenerateColumns="false" InitialExpandDepth="0" InitialDataBindDepth="0" EnableDataViewState="true" DataKeyFields="Report" EnableAjax="true" AjaxIndicator-Enabled="True" AjaxIndicator-BlockArea="Control" AjaxIndicator-BlockCssClass="ig_AjaxIndicatorBlock" Height="100%" Width="100%"> <Columns> </Columns> <Behaviors> <ig:Activation Enabled="true" /> <ig:Selection RowSelectType="Multiple" CellClickAction="Row" Enabled="true" /> <ig:Sorting SortingMode="Single" Enabled="true" /> <ig:Filtering Alignment="Top" Visibility="Visible" Enabled="true" AnimationEnabled="true" /> <ig:Paging PagerAppearance="Both" PagerMode="NumericFirstLast" QuickPages="3" PageSize='<%$ appSettings:PageSize_ReportDataMapGrid%>' FirstPageText="First" LastPageText="Last" > </ig:Paging> </Behaviors> <EmptyRowsTemplate> <div style="text-align: center;"> <br /> <br /> <img src="Images/information.gif" alt="!" align="middle" /> <asp:Label ID="noDataLabel" runat="server" Text="No records found." Font-Size="Small" ForeColor="#000099" Font-Bold="True"> </asp:Label> </div> </EmptyRowsTemplate> <ErrorTemplate> <div style="text-align: center; width: 800px;"> <img src="Images/error.png" alt="!" align="middle" /> <asp:Label ID="errorLabel" runat="server" Text="An error has occurred! Please contact support." Font-Size="Small" ForeColor="#CC0000" Font-Bold="True"> </asp:Label> </div> </ErrorTemplate> <ClientEvents Initialize="intializeGrid" /> </ig:WebDataGrid> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnClear" EventName="Click" /> </Triggers> </asp:UpdatePanel>
the grid is part of a custom control. When the page call the ExecuteReport method on the custom control, the grid is loaded and binded.
For the filtering, sorting and paging to work, I have this in the page_load method:
if (this.IsPostBack && this.ReportData != null) { this.reportDataIGGrd.Columns["TimeInMinutes"].FormatFieldMethod += new FormatRecordItemValue(FormatTimeSpan); this.reportDataIGGrd.DataSource = this.ReportData; }
The ReportData property is a cached CollectionBase object containing a list of reportdatarow objects (custom).
I have 2 problems:
1 - My page has another UpdatePanel. When the page updatepanel is triggered, my custom control page_load is called and the datasource is set in the page_load. This cause the grid to be emptied on my screen.
2- In my custom control, I have a button that causes a postback. When the page is posted back, I have to read the grid selection, but because the datasource is set, the list of selected rows is cleared. I tried to read the grid selection obejct before setting the datasource, but it is empty in the page_load. I can't access it before getting in the OnClick event of my button.
So, my question is, is it possible to know when the grid is posting back for a filtering, paging or sorting event to make sure I only set the datasource when one of these events are happening?
Thanks
Yves
.
Hi Yves,
One quick approach to "know" on postback if the postback was initiated by a behavior would be to handle the "ing" client-side events for the behaviors, i.e. DataFiltering, ColumnSorting, PageIndexChanging .
You can add a HiddenField control to your page and set its value in the handlers of the client-side events, for instance:
function WebDataGrid1_Filtering_DataFiltering(sender, eventArgs){document.getElementById("HiddenField1").value = "true";
Then in Page_Load you can check the value of the HiddenField control and rebind accordingly (and also reset the value of the hiddenField to false for example)
Please tell me if this helps.
ok, I had to use both "ing" and "ed" methods, The "ing" to set the hidden field value and the "ed" to clear it., because even if I was clearing the hidden field value from the server, the value was always sent back on postbacks even if the hiddenfied was in the update panel with the grid...
Thanks for your help
Please do not hesitate to contact me if you need further assistance.