This is a migrated thread and some comments may be shown as answers.

Grid Not sorting

2 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Klein
Top achievements
Rank 1
Eric Klein asked on 30 Sep 2010, 07:02 PM
I have a radgird on the screen andt uses onneeddata to fill the grid.  The filtering is done by dropdowns on the screen.
Here is my grid.
<rad:radgrid id="gridFilings" runat="server"
                allowsorting="True" autogeneratecolumns="False"
                enableajax="True" enableajaxloadingtemplate="True" gridlines="None" loadingtemplatetransparency="50"
                showstatusbar="True" skin="Windows"
                width="98%" ShowGroupPanel="True" AllowPaging="false" OnItemDataBound="gridFilings_ItemDataBound"
                OnNeedDataSource ="gridFilings_NeedDataSource"
                
                  
                <ClientSettings AllowDragToGroup="True">
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
                <MasterTableView AllowCustomPaging="True" DataKeyNames="FileID"
                     AutoGenerateColumns="False" DataSourcePersistenceMode="NoPersistence" AlternatingItemStyle-BackColor="ControlLight">
                    <Columns>  
                        <rad:GridBoundColumn DataField="FileID"
                        UniqueName="FileID" Groupable="False" AllowSorting="True" Visible="True" HeaderText="Job #" HeaderStyle-CssClass="headerLeft" DataType="System.String">
                        </rad:GridBoundColumn>              
                         <rad:GridTemplateColumn DataField="ClientName" HeaderText="Client Name" HeaderStyle-CssClass="headerLeft"
                         SortExpression="ClientName" UniqueName="ClientName" GroupByExpression="ClientName Group By ClientName">
                         <itemTemplate>
                             <%# Eval("ClientName")%>
                         </itemTemplate>
                         </rad:GridTemplateColumn>
                         <rad:GridTemplateColumn DataField="GroupName" HeaderText="Group" HeaderStyle-CssClass="headerLeft"
                         SortExpression="GroupName" UniqueName="GroupName" GroupByExpression="GroupName Group By GroupName">
                         <ItemTemplate>
                             <%# Eval("GroupName")%>  
                         </ItemTemplate>
                         </rad:GridTemplateColumn>                                                                          
                         <rad:GridTemplateColumn HeaderText="Operator" HeaderStyle-CssClass="headerLeft"
                         SortExpression="AssignedTo" UniqueName="OperatorTemplate" GroupByExpression="AssignedTo Group By AssignedTo">
                         <ItemTemplate>
                             <asp:DropDownList ID="OperatorDropDown" runat="server" EnableViewState="false"></asp:DropDownList>                     
                         </ItemTemplate>
                         </rad:GridTemplateColumn>                                                                          
                         <rad:GridTemplateColumn DataField="DateIn" HeaderText="Date In" HeaderStyle-CssClass="headerLeft"
                         SortExpression="DateIn" UniqueName="DateIn" GroupByExpression="DateIn Group By DateIn" >
                         <ItemTemplate>
                             <%# String.Format("{0:MM/dd/yyyy}", Eval("DateIn"))%>  
                         </ItemTemplate>
                         </rad:GridTemplateColumn>
                         <rad:GridTemplateColumn DataField="DueDate" 
                         HeaderText="Due Date" HeaderStyle-CssClass="headerLeft" SortExpression="DueDate" UniqueName="DueDate" GroupByExpression="DueDate Group By DueDate">
                         <ItemTemplate>
                             <%# String.Format("{0:MM/dd/yyyy}", Eval("DueDate"))%>
                         </ItemTemplate>
                         </rad:GridTemplateColumn>
                         <rad:GridTemplateColumn DataField="FileTypeName" HeaderText="Form Type" HeaderStyle-CssClass="headerLeft"
                         SortExpression="FileTypeName" UniqueName="FileTypeName" Groupable="False">
                             <ItemTemplate>
                             <%# Eval("FileTypeName")%>
                             </ItemTemplate>
                         </rad:GridTemplateColumn>
                         <rad:GridTemplateColumn DataField="ConvertedPageCount" Groupable="false" HeaderText="Converted<br>Page Count" HeaderStyle-CssClass="headerRight" ItemStyle-HorizontalAlign="Right" 
                          UniqueName="ConvertedPageCount">
                             <ItemTemplate>
                                 <%# Eval("ConvertedPageCount")%>
                             </ItemTemplate>
                         </rad:GridTemplateColumn>
                         <rad:GridTemplateColumn DataField="ChangedPageCount" Groupable="false" HeaderText="Changed<br>Page Count" HeaderStyle-CssClass="headerRight" ItemStyle-HorizontalAlign="Right" 
                          UniqueName="ChangedPageCount">
                             <ItemTemplate>
                                 <%# Eval("ChangedPageCount")%>
                             </ItemTemplate>
                         </rad:GridTemplateColumn>                         
                         <rad:GridTemplateColumn DataField="ConversionType" Groupable="false" HeaderText="Conversion" ItemStyle-HorizontalAlign="Center" 
                          UniqueName="ConversionType">
                             <ItemTemplate>
                                 <%# Eval("ConversionType")%>
                             </ItemTemplate>
                         </rad:GridTemplateColumn
                        <rad:GridBoundColumn DataField="FileStatusTypeID" 
                        UniqueName="FileStatusTypeID" Groupable="False" AllowFiltering="False" Visible="False">                    
                        </rad:GridBoundColumn>
                        <rad:GridBoundColumn DataField="AssignedTo"
                        UniqueName="AssignedTo" Groupable="False" AllowFiltering="False" Visible="False">                    
                        </rad:GridBoundColumn>
                           
                        <rad:GridTemplateColumn HeaderText="Status" HeaderStyle-CssClass="headerLeft" AllowFiltering="False" SortExpression="FileStatusTypeID" UniqueName="FileStatusTypeIDTemplate" GroupByExpression="FileStatusTypeID Group By FileStatusTypeID">
                        <ItemTemplate>
                        <asp:DropDownList ID="StatusTypeID" runat="server" EnableViewState="false" DataTextField="FileStatusTypeName" DataValueField="FileStatusTypeID"></asp:DropDownList>                
                        </ItemTemplate>
                        </rad:GridTemplateColumn>                                                 
                         <rad:GridTemplateColumn AllowFiltering="False" UniqueName="ViewFiling" Groupable="false">
                           <ItemTemplate>
                                <a href="javascript:openDialog('ViewFiling.aspx?fileid=<%# Eval("FileID")%>', 800, 600, 'file', 'scrollbars=yes,resizable=yes');">
                                    <img alt="View Filing" border="0" src="RadControls/Grid/Skins/Windows/View.gif"
                                        title="View Filing" /></a>
                           </ItemTemplate>
                         </rad:GridTemplateColumn>                                                
                         <rad:GridTemplateColumn AllowFiltering="False" UniqueName="EditFiling" Groupable="false">
                           <ItemTemplate>
                                <a href="EditFiling.aspx?fileid=<%# Eval("FileID")%>">
                                    <img alt="Edit Filing" border="0" src="RadControls/Grid/Skins/Windows/Edit.gif"
                                        title="Edit Filing" /></a>
                           </ItemTemplate>
                         </rad:GridTemplateColumn>
                        <rad:GridTemplateColumn AllowFiltering="False" UniqueName="DocumentLink" Groupable="false">
                            <ItemTemplate>
                                <a href="javascript:openDialog('FileManager.aspx?fileid=<%# Eval("FileID")%>', 800, 600, 'file', 'scrollbars=yes,resizable=yes');">
                                    <img alt="View Files" border="0" src="RadControls/Grid/Skins/Windows/folder.gif"
                                        title="View Files" /></a>
                            </ItemTemplate>
                            <HeaderStyle Width="20px" />
                        </rad:GridTemplateColumn
                        <rad:GridTemplateColumn DataField="GroupID"  
                         UniqueName="GroupID" Display="false">
                         <ItemTemplate>
                             <%# Eval("GroupID")%>
                         </ItemTemplate>
                         </rad:GridTemplateColumn>                        
                    </Columns>
                    <ExpandCollapseColumn Resizable="False" Visible="False">
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <RowIndicatorColumn Visible="False">
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>                   
                </MasterTableView>    
            </rad:radgrid>

and this is the code behind
protected void gridFilings_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            SqlDataSource1.SelectCommand= "SELECT [FileID], [ClientID], [ClientName], [DateIn], [DueDate], [FileTypeName], [FileLocation], [FileStatusTypeName], [FileStatusTypeID] , [GroupID], [GroupName], [PageCount], [ConvertedPageCount], [ChangedPageCount], [ConversionType], IsNull([AssignedTo], '') as 'AssignedTo' FROM [FileDetailView] WHERE  [FileStatusTypeID] <= 90 ";
  
            if (Page.User.IsInRole("GROUP"))
                SqlDataSource1.SelectCommand += " and [GroupID] = " + Session["GroupID"].ToString();
            else if (Page.User.IsInRole("CLIENT"))
                SqlDataSource1.SelectCommand += " and [ClientID] = " + Session["ClientID"].ToString() + " and FileStatusTypeID = 0";
              
            if (ClientName.SelectedValue.Length > 0)
                SqlDataSource1.SelectCommand += " and ClientID = " + ClientName.SelectedValue;
  
            if (ClientGroup.SelectedValue.Length > 0)
                SqlDataSource1.SelectCommand +=  " and GroupID = " + ClientGroup.SelectedValue;               
  
            if (StartDueDate.Text.Length > 0)
            {
                if (EndDueDate.Text.Length > 0)
                    SqlDataSource1.SelectCommand +=  " and (DueDate >= '" + StartDueDate.Text + "' and DueDate <= '" + EndDueDate.Text + "')";                    
                else
                    SqlDataSource1.SelectCommand +=  " and DueDate = '" + StartDueDate.Text + "'";                    
            }
  
            if (StartDateIn.Text.Length > 0)
            {
                if (EndDateIn.Text.Length > 0)
                    SqlDataSource1.SelectCommand += " and (DateIn >= '" + StartDateIn.Text + "' and DateIn <= '" + EndDateIn.Text + "')";                    
                else
                    SqlDataSource1.SelectCommand +=  " and DateIn = '" + StartDateIn.Text + "'";                    
            }
  
            SqlDataSource1.SelectCommand += " Order by FileStatusTypeID";
              
            gridFilings.DataSource = SqlDataSource1;

The issue I am having is when the user click the header to sort you see the icon popup like it is working but it does not sort the grid.  I have put a stop in the NeedDataSource and when the grid sorts it runs throught this logic, so I am assumin git is lossing the sorting and just reloading the grid.  Is there a way I can get the sort informatioan and just add an orderby in the sql?

2 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 30 Sep 2010, 07:54 PM
Hello Eric,

Why don't you move that code into your Page_Load method instead. The reason being, your including an order by command in the select command, which is most likely overwriting the one being passed by the RadGrid. See if that fixes your issue.

Otherwise, the only other option would be to set OverrideDataSourceControlSorting="true", which forces the RadGrid control to do the sorting, instead of passing it into the datasource.

I hope that helps.
0
Eric Klein
Top achievements
Rank 1
answered on 30 Sep 2010, 08:32 PM
thanks the OverrideDataSourceControlSorting="true"  worked.  moving the page_Load event did not.
Tags
Grid
Asked by
Eric Klein
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Eric Klein
Top achievements
Rank 1
Share this question
or