CodeSmith Community
Your Code. Your Way. Faster!

Sorting with EntityGridView and DataSource

Latest post 04-14-2007 12:39 PM by mike123. 1 replies.
  • 04-13-2007 8:29 AM

    • rithomas
    • Not Ranked
    • Joined on 04-13-2007
    • Posts 2
    • Points 100

    Sorting with EntityGridView and DataSource

    I am trying to sort using an EntityGridView, but it is not working.  Click on column headers refreshes the page, but sorting does not occur.  Can anybody help?  Here is my markup:

     <data:EntityGridView
                                    AllowExportToExcel="false"
                                    ID="gvAppointments"
                                    DataKeyNames="ID"
                                    runat="server"
                                    AutoGenerateColumns="false"
                                    DataSourceID="dsAppointments"
                                    DefaultSortColumnName="StartTime"
                                    DefaultSortDirection="Descending"
                                    OnSorting="gvAppointments_Sorting"
                                    OnSelectedIndexChanged="gvAppointments_SelectedIndexChanged"
                                    AllowSorting="true"
                                    AllowPaging="true"
                                    CssClass="DataGrid"
                                    HeaderStyle-ForeColor="White"
                                    HeaderStyle-BackColor="#333366"
                                    RowStyle-BackColor="#fbf4fb"
                                    CellPadding="3"
                                    CellSpacing="0"
                                    AlternatingRowStyle-BackColor="White"
                                    RowStyle-Font-Size="x-small"
                                    AlternatingRowStyle-Font-Size="x-small"
                                    HeaderStyle-Font-Size="x-small">
                                        <Columns>
                                            <asp:CommandField ShowSelectButton="true"/>
                                            <asp:BoundField DataField="StartTime" HeaderText="Start Time" SortExpression="StartTime" />
                                            <asp:BoundField DataField="EndTime" HeaderText="End Time" SortExpression="EndTime" />
                                            <asp:BoundField DataField="AppointmentType" HeaderText="Type" SortExpression="AppointmentType" />
                                            <asp:BoundField DataField="Cancelled" HeaderText="Cancelled" SortExpression="Cancelled" />
                                            <asp:BoundField DataField="CareProvider" HeaderText="Provider" SortExpression="CareProvider" />
                                            <asp:BoundField DataField="Facility" HeaderText="Facility" SortExpression="Facility" />
                                            <asp:BoundField DataField="Recommendation" HeaderText="Recommendation" SortExpression="Recommendation" />
                                            <asp:TemplateField HeaderText="">
                                             <ItemTemplate>
                                               <asp:Button ID="btnAptEdit"
                                                 OnClientClick="<%# Eval(&quot;ID&quot;, &quot;return EditAppointment('{0}', 'edit');&quot;) %>"
                                                 runat="server"
                                                 text="Edit...">
                                                 </asp:Button>
                                             </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </data:EntityGridView>

     <data:PatientAppointmentDataSource EnableDeepLoad="true" ID="dsAppointments" EnableSorting="true" SelectMethod="GetByPatientID" runat="server">
            <DeepLoadProperties Method="IncludeChildren">
                <Types>
                    <data:PatientAppointmentProperty Name="Reason" />
                    <data:PatientAppointmentProperty Name="Facility" />
                    <data:PatientAppointmentProperty Name="CareProvider" />
                    <data:PatientAppointmentProperty Name="Reason" />
                </Types>
            </DeepLoadProperties>
            <Parameters>
                <asp:QueryStringParameter Type="Int32" Name="PatientID" QueryStringField="PatientID" />
            </Parameters>
        </data:PatientAppointmentDataSource>
       

    Filed under: ,
    • Post Points: 35
  • 04-14-2007 12:39 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 734
    • Points 17,040

    Re: Sorting with EntityGridView and DataSource

    rithomas,

     You could do this:

        protected void Page_Load(object sender, EventArgs e)
        {
            gvAppointments.Sorting += new GridViewSortEventHandler(gvAppointments_Sorting);
        }

        void gvAppointments_Sorting(object sender, GridViewSortEventArgs e)
        {
            gvAppointments.DefaultSortColumnName = e.SortExpression;
            gvAppointments.DefaultSortDirection = e.SortDirection
    ;
        }

    or using Find method with parameterized filter:

     <data:PatientAppointmentDataSource EnableDeepLoad="true" ID="dsAppointments" EnableSorting="true" SelectMethod="GetByPatientID" runat="server">
            <DeepLoadProperties Method="IncludeChildren">
                <Types>
                    <data:PatientAppointmentProperty Name="Reason" />
                    <data:PatientAppointmentProperty Name="Facility" />
                    <data:PatientAppointmentProperty Name="CareProvider" />
                    <data:PatientAppointmentProperty Name="Reason" />
                </Types>
            </DeepLoadProperties>
            <Parameters>
                     <data:SqlParameter Name="Parameters">
                        <Filters>
                            <data:PatientAppointmentFilter  Column="PatientID" ControlID="__Page" PropertyName="PatientID" />
                        </Filters>
                    </data:SqlParameter>
                    <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />

            </Parameters>
        </data:PatientAppointmentDataSource>

       

    code-behind: 

        public String PatientID
        {
            get
            {
                String q = Request.QueryString["PatientID"];
                if (q != null)
                {
                    return q.ToString();
                }
                return string.Empty;
            }
        }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems