Dear All,
I have implemented a GridView Control which can be sorted by clicking the Header Colom, with a Filter, which is bound to a CSLA DataSource. I have followed same basic idea Proejct Tracker Application, but since there is no implementation for sorting in the sample applicaiton, I had to do it on my own.
Here is the Filter Parameter/GridView Source:
<fieldset class="ParameterList" >
<legend><asp:Label ID="lblTitleText" runat="server" Text='Enter Search Parameters (Partial Match "%" Supported)' ></asp:Label></legend>
<asp:Panel ID="FilterPanel" runat="server">
<div class="ParameterItem">
<asp:Label ID="lblRequestID" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtRequestID" Text="Request ID:" />
<asp:TextBox ID="txtRequestID" CssClass="ParameterItemInput" runat="server"/>
</div>
<div class="ParameterItem" >
<asp:Label ID="lblPatientID" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtPatientID" Text="Patient ID:"/>
<asp:TextBox ID="txtPatientID" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblTechnicanID" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtTechnicanID" Text="Technician ID:"/>
<asp:TextBox ID="txtTechnicanID" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblDoctorID" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtDoctorID" Text="Doctor ID:"/>
<asp:TextBox ID="txtDoctorID" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblPatientName" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtPatientName" Text="Patient Name:" />
<asp:TextBox ID="txtPatientName" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblTechnicianName" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtTechnicianName" Text="Technician Name:" />
<asp:TextBox ID="txtTechnicianName" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblDoctorName" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtDoctorName" Text="Doctor Name:" />
<asp:TextBox ID="txtDoctorName" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ParameterItem" >
<asp:Label ID="lblSinceMonthsBack" CssClass="ParameterItemLabel" runat="server" AssociatedControlID="txtSinceMonthsBack" Text="Since Months Back:" />
<asp:TextBox ID="txtSinceMonthsBack" CssClass="ParameterItemInput" runat="server" />
</div>
<div class="ButtonList">
<asp:Button ID="btnFilterActivate" CssClass="FilterActivate" runat="server" Text="Activate Filter" />
<asp:Button ID="btnFilterClear" CssClass="FilterClear" runat="server" Text="Clear Filter" />
</div>
</asp:Panel>
</fieldset>
<asp:GridView ID="gvLabRequestList" CssClass="GridView" runat="server" AutoGenerateColumns="False" DataSourceID="dtaLabRequestList" AllowPaging="True" PageSize="15" AllowSorting="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<Columns>
<asp:BoundField DataField="LabRequestID" HeaderText="Request ID" ReadOnly="True"
SortExpression="Id" />
<asp:BoundField DataField="LabRequestDateDMYStr" HeaderText="Request Date (DMY)" ReadOnly="True"
SortExpression="LabRequestDate" />
<asp:BoundField DataField="PateintNameID" HeaderText="Pateint ID-Name" ReadOnly="True"
SortExpression="PateintNameID" />
<asp:BoundField DataField="DiagnosisDescEng" HeaderText="Diagnosis" ReadOnly="True"
SortExpression="DiagnosisDescEng" />
<asp:CheckBoxField DataField="CompletedFlag" HeaderText="Completed?" SortExpression="CompletedFlag" />
</Columns>
<AlternatingRowStyle CssClass="AlternateRowStyle" />
<RowStyle CssClass="RowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<FooterStyle cssclass="FooterStyle" />
<PagerStyle cssclass="PagerStyle"/>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
</asp:GridView>
Here is the code-behind:
Private Function GetLabRequestList(ByVal e As Csla.Web.SelectObjectArgs) As Csla.SortedBindingList(Of MyOrg.Library.Clinic.LabRequestInfo)
Dim myObjSorted As Csla.SortedBindingList(Of MyOrg.Library.Clinic.LabRequestInfo)
Dim objList As Clinic.LabRequestList
Dim ObjSortProperty As String
myObjSorted = Session("BusinessObject")
If myObjSorted Is Nothing OrElse Not TypeOf myObjSorted Is Csla.SortedBindingList(Of Clinic.LabRequestInfo) Then
objList = _
Clinic.LabRequestList.GetLabRequestList( _
txtRequestID.Text, txtPatientID.Text, txtTechnicanID.Text, _
txtDoctorID.Text, txtPatientName.Text, txtTechnicianName.Text, _
txtDoctorName.Text, txtSinceMonthsBack.Text _
)
myObjSorted = New SortedBindingList(Of Clinic.LabRequestInfo)(objList)
If Not e.SortProperty Is Nothing Then
myObjSorted.ApplySort(e.SortProperty, e.SortDirection)
End If
Session("BusinessObject") = myObjSorted
Else
If myObjSorted.SortProperty Is Nothing Then
ObjSortProperty = ""
Else
ObjSortProperty = myObjSorted.SortProperty.Name
End If
If Not String.IsNullOrEmpty(e.SortProperty) AndAlso _
(e.SortProperty <> ObjSortProperty OrElse e.SortDirection <> myObjSorted.SortDirection) _
Then
myObjSorted.ApplySort(e.SortProperty, e.SortDirection)
Session("BusinessObject") = myObjSorted
End If
End If
Return myObjSorted
End Function
Protected Sub dtaLabRequestList_SelectObject(ByVal sender As System.Object, ByVal e As Csla.Web.SelectObjectArgs) Handles dtaLabRequestList.SelectObject
Dim myObj As Csla.SortedBindingList(Of MyOrg.Library.Clinic.LabRequestInfo)
myObj = GetLabRequestList(e)
e.BusinessObject = myObj
End Sub
Protected Sub btnFilterActivate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilterActivate.Click
Session("BusinessObject") = Nothing
gvLabRequestList.DataBind()
End Sub
Appreciate your feedback on the above code sample.
Tarek.
I am posting again hoping to get feedback.
Tarek.
Copyright (c) Marimer LLC