CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 1/24/2006 6:55:57 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 185 Views: 237 Favorited: 0 Favorite
186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|
jonefer
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource5/28/2007 7:24:10 PM

0

Let me preface this by - Like donjuanwu... my gridview disappears when I click any header - HOWEVER, I am not using any paging, my business did not request paging, they prefer to scroll down the page. 

 

Please help me with the 2 following strings....

This is how they appear in your post: 

private string GridViewSortDirection

    {

        get { return ViewState["SortDirection"] as string ?? "ASC"; }

        set { ViewState["SortDirection"] = value; }

    }

 

     

 

 

For my application, I have to translate them to Visual Basic

So they look like this:

 

Private Property GridViewSortDirection() As String
 Get
          Return ViewState("SortDirection") as String ?? "ASC"
 End Get
 Set (ByVal Value As String)
          ViewState("SortDirection") = value
 End Set
End Property
 
 
 
    Private Property GridViewSortBLOCKED EXPRESSION As String
     Get
          Return ViewState("SortBLOCKED EXPRESSION as String ?? String.Empty
     End Get
     Set (ByVal Value As String)
          ViewState("SortBLOCKED EXPRESSION = value
     End Set
    End Property
 

 I get a blue squiggly line under both of these --------> String ?? "ASC"   and   as String ?? String.Empty

"End of Statement Expected"

 

But clearly you are running this code as is.... what do I need to do to adjust them so they work for me? 

 

I have successfully translated the other necessary components.

 

thekid
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource5/29/2007 4:16:42 PM

0

StrongTypes:

Here's the live working example with source code: GridView Sorting/Paging w/o a DataSourceControl DataSource

I had to tweak the code a little to make sorting work in both directions.

Enjoy.
Ryan

 

 

This is almost exactly what I am looking for, is this possible via stored procedures too? 

Raafat4
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/12/2007 9:31:21 AM

0

Hi,

I applied the code which you wrote it,There are no Errors but the Sorting failed.

Att1. I am using Microsoft Enterprise Library.

Att2.I am working as NTier and my code available on Data Access Layer.

Can you help me in this regards.

Thank you in advance

neoleela
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/14/2007 8:48:21 AM

0

The new code worked well. If the datasource is not from database, then we have to use one line of code to add the grid's datasource into viewstate.

ViewState["gridview_DataSource"] = gridview.DataSource;

And later, whereever datatable is needed, add this line of code.

(DataTable)ViewState["gridMyCases_DataSource"]

The solution just works too good. Thanks Ryan.

aishas
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/15/2007 9:29:40 AM

0

test

mliolios
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/28/2007 1:37:50 PM

0

Paula,  Is it possible to explaine what did you do, or better to post once again the final working code?

Thanks in advande

jeeva.net
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/28/2007 6:38:19 PM

0

Hi Ryan,

That was a nice article. i tried converting the same to VB.net.. i'm hitting on an error in the following piece of code

Protected Sub SearchGrid_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SearchGrid.Sorting
        Dim datatab As DataTable = SearchGrid.DataSource
        Dim datavw As New DataView(datatab)
        datavw.Sort = e.SortExpression.ToString + " " + ConvertSortDirectionToSql(e.SortDirection)           'this is where i get the error
        SearchGrid.DataSource = datavw
        SearchGrid.DataBind()

    End Sub

 When i click on the first column to sort,   it throws this message "Conversion from string "StudentID " to type 'Double' is not valid"
Can you please help me ? Please see i'm using VB.net
 
My complete code is as follows
 
Private Function ConvertSortDirectionToSql(ByVal sortdirect As String) As SortDirection
        Dim newsortdirection As String
        Select Case (sortdirect)
            Case SortDirection.Ascending
                newsortdirection = "asc"
            Case SortDirection.Descending
                newsortdirection = "desc"
            Case Else
                newsortdirection = "asc"
        End Select
        Return (newsortdirection)
    End Function

 Protected Sub SearchGrid_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SearchGrid.Sorting
        Dim datatab As DataTable = SearchGrid.DataSource
        Dim datavw As New DataView(datatab)
        datavw.Sort = e.SortExpression.ToString + " " + ConvertSortDirectionToSql(e.SortDirection)
        SearchGrid.DataSource = datavw
        SearchGrid.DataBind()

    End Sub
 

Regards,
Jeeva

rahilameen
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/4/2007 1:15:30 PM

0

 

hi,

i am a new member of this goup and new to asp.net too.

i tried the above code to sort the grid manually.but its showing following error

what to do?

please help me

i had stucked at this level of my program.

regards,

thanks in advance,

rahilameen
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/4/2007 1:17:12 PM

0

hi,

i am a new member of this goup and new to asp.net too.

i tried the above code to sort the grid manually.but its showing following error

"The name 'sortDirection' does not exist in the current context"

what to do?

please help me

i had stucked at this level of my program.

regards,

thanks in advance,

Raafat4
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/4/2007 1:45:48 PM

0

Hi ,

Write this function:

private string ConvertSortDirectionToSql(SortDirection sortDireciton)

{

string newSortDirection = String.Empty;switch (sortDireciton)

{

case SortDirection.Ascending:

newSortDirection = "ASC";

break;

case SortDirection.Descending:

newSortDirection = "DESC";

break;

}

return newSortDirection;

}

There is an event in the GridView events called Sorting ,put the code velow in it:

protected void gvDataSources_Sorting(object sender, GridViewSortEventArgs e)

{

DataTable dt = new DataTable();

dt = LoadDataSources().Tables[0]; // LoadDataSources() function that return DataSet and the GridView Get its data from it

if (dt != null)

{

DataView dvSort = new DataView(dt);

dvSort.Sort = e.SortExpression;

dvSort.Sort = e.SortExpression +
" " + ConvertSortDirectionToSql(e.SortDirection);

gvDataSources.DataSource = dvSort;

gvDataSources.DataBind();

}

}

 

Regards,

Ra'fat

mcmillan_associ
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/4/2007 10:53:34 PM

0

This is very helpful but can someone translate this code in to VB.NET for those of us noobies out there:

 

private string ConvertSortDirectionToSql(SortDirection sortDireciton)

{

string newSortDirection = String.Empty;

switch (sortDirection)

{

case SortDirection.Ascending:newSortDirection = "ASC";

break;

case SortDirection.Descending:

newSortDirection = "DESC";

break;

}

return newSortDirection

}

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

gridView.PageIndex = e.NewPageIndex;

gridView.DataBind();

}

protected void gridView_Sorting(object sender, GridViewSortEventArgs e)

{

DataTable dataTable = gridView.DataSource
as DataTable;if (dataTable != null)

{

DataView dataView = new DataView(dataTable);

dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

gridView.DataSource = dataView;

gridView.DataBind();

}

}

mcmillan_associ
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/4/2007 11:25:06 PM

0

Ryan - this is very helpful but can you post this code in VB.NET?

Raafat4
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/5/2007 9:22:01 AM

0

Hi,

I am Ra'fat not Ryan ,

But i forget  the VB.NET Syntax, specially Function Definition

Try this code:

private string ConvertSortDirectionToSql(SortDirection sortDireciton)

{

Dim newSortDirection as String

newSortDirection = " "

switch (sortDireciton)

{

case SortDirection.Ascending:

newSortDirection = "ASC"

break

case SortDirection.Descending:

newSortDirection = "DESC"break

}

return newSortDirection

}

There is an event in the GridView events called Sorting ,put the code velow in it:

protected void gvDataSources_Sorting(object sender, GridViewSortEventArgs e)

{

Dim dt as new DataTable

dt = LoadDataSources().Tables(0); ' LoadDataSources() function that return DataSet and the GridView Get its data from it

if (dt <> null) Dim dvSortas new DataView(dt)

dvSort.Sort = e.SortExpression

dvSort.Sort = e.SortExpression &
" " & ConvertSortDirectionToSql(e.SortDirection)

gvDataSources.DataSource = dvSort

gvDataSources.DataBind()

End If

}

 

Best Regards

Ra'fat

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/5/2007 2:21:04 PM

0

Ryan - this is very helpful but can you post this code in VB.NET?

There is a VB.NET version.


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
peterthegreat
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/5/2007 2:52:30 PM

0

like you i am a new member,also to asp.net.

my question is can you not accomplish this via asp.net?

i am not sure what you are trying to achieve.but in time i suppose i will come across its use.so i have decided to save a copy of code...just in case.

i would like to create own websites,like you.

are there any useful sites where you can get useful code/examples from

pelegk2
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/10/2007 9:18:01 PM

0

when i am using the

productsGridView_PageIndexChanging

i see in the debbuger that the function is called twice

why is that?

 

thnaks i nadvance

peleg


Israel the best place to live in - after heaven (but no one wants to go there so fast!)
Mr Blue Coat
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/10/2007 10:35:06 PM

0

 Excellent post - Thanks!

Here's my newbie ASP.NET variation for SQL Server using Session variables (instead of ViewState) and support for paging, sorting, data filtering and selecting:

 web.config:

<connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=<SERVER>;Initial Catalog=<DATABASE>;Persist Security Info=True;User ID=<USER>;Password=<PASSWORD>" providerName="System.Data.SqlClient"/>
  </connectionStrings>

app_code (DatabaseConnection.vb):

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient

Public Class DatabaseConnection

    Public Shared connection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)

End Class

app_code (Utils.vb):

Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports System.Data
Imports System.Data.SqlClient
Imports DatabaseConnection

Public Class Utils

Public Shared Function GetCompareStatement(ByVal firstValue As String, ByVal secondValue As String, ByVal operation As String) As String
        Select Case operation
            Case "Contains"
                Return "LIKE '%" + firstValue + "%' "
            Case "Begins with"
                Return "LIKE '" + firstValue + "%' "
            Case "Ends with"
                Return "LIKE '%" + firstValue + "' "
            Case "Equals"
                Return "= '" + firstValue + "' "
            Case "Date Equals"
                Return "= CONVERT(DATETIME, '" + firstValue + "', 101) "
            Case "After"
                Return "> CONVERT(DATETIME, '" + firstValue + "', 101) "
            Case "Before"
                Return "< CONVERT(DATETIME, '" + firstValue + "', 101) "
            Case "Between"
                Return "BETWEEN CONVERT(DATETIME, '" + firstValue + "', 101) AND CONVERT(DATETIME, '" + secondValue + "', 101) "
            Case Else
                Return ""
        End Select
    End Function

    Public Shared Sub BindPagingSortingGridView(ByVal query As String, ByVal gridViewControl As GridView)
        'Binds Paging/Sorting GridView with data from the specified query
        Dim sqlComm As SqlCommand
        Dim sqlReader As SqlDataReader
        Dim dataTableControl As New DataTable()
        Dim dataTableRowCount As Integer

        sqlComm = New SqlCommand(query, connection)
        sqlReader = sqlComm.ExecuteReader()
        dataTableControl.Load(sqlReader)
        dataTableRowCount = dataTableControl.Rows.Count

        If dataTableRowCount > 0 Then
            gridViewControl.DataSource = dataTableControl
            gridViewControl.DataBind()
        End If

        sqlReader.Close()
    End Sub

    Public Shared Function SortDataTable(ByVal dataTable As DataTable, ByVal isPageIndexChanging As Boolean) As DataView
        If Not dataTable Is Nothing Then
            Dim dataView As New DataView(dataTable)
            If GridViewSortExpression <> String.Empty Then
                If isPageIndexChanging Then
                    dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)
                Else
                    dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GetSortDirection())
                End If
            End If
            Return dataView
        Else
            Return New DataView()
        End If
    End Function

    Public Shared Property GridViewSortBLOCKED EXPRESSION As String
        Get
            Return IIf(Current.Session("SortBLOCKED EXPRESSION = Nothing, String.Empty, Current.Session("SortBLOCKED EXPRESSION)
        End Get
        Set(ByVal value As String)
            Current.Session("SortBLOCKED EXPRESSION = value
        End Set
    End Property

    Private Shared Function GetSortDirection() As String
        Select Case GridViewSortDirection
            Case "ASC"
                GridViewSortDirection = "DESC"
            Case "DESC"
                GridViewSortDirection = "ASC"
        End Select
        Return GridViewSortDirection
    End Function

    Public Shared Property GridViewSortDirection() As String
        Get
            Return IIf(Current.Session("SortDirection") = Nothing, "ASC", Current.Session("SortDirection"))
        End Get
        Set(ByVal value As String)
            Current.Session("SortDirection") = value
        End Set
    End Property

End Class

aspx page:

                <asp:GridView ID="SupplierGridView" CssClass="datatable" Width="100%" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                        EmptyDataText="No records found" PageSize="15" runat="server">
                    <Columns>
                        <asp:ButtonField ButtonType="Link" Text="Select" CommandName="SELECT" />
                        <asp:BoundField DataField="ENT_SUPPLIER_NBR" HeaderText="ESD Number" SortExpression="ENT_SUPPLIER_NBR" />
                        <asp:BoundField DataField="SUP_NAME1" HeaderText="Name" SortExpression="SUP_NAME1" />
                        <asp:BoundField DataField="STREET" HeaderText="Street" SortExpression="STREET" />
                        <asp:BoundField DataField="CITY" HeaderText="City" SortExpression="CITY" />
                        <asp:BoundField DataField="STATE_REGION" HeaderText="State" SortExpression="STATE_REGION" />
                        <asp:BoundField DataField="ACTIVE" HeaderText="ACTIVE" SortExpression="ACTIVE" />
                    </Columns>
                </asp:GridView>

 vb page:

Imports System.Data
Imports System.Data.SqlClient
Imports Utils
Imports DatabaseConnection

...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       If Not Page.IsPostBack Then
            ' Clear user paging/sort
            Session("CurrentPage") = 0
            Session("SortBLOCKED EXPRESSION = Nothing
            GridViewSortDirection = "ASC"
            ' Set current query
            Session("CurrentQuery") = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_SUPPLIERS WHERE ENT_SUPPLIER_NBR IS NOT NULL AND ACTIVE = 'Active' ORDER BY SUP_NAME1 ASC"
        End If

        ' Bind GridView to current query
        connection.Open()
        BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
        connection.Close()

End Sub

 Protected Sub ApplyFilterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ApplyFilterButton.Click
        ' Filter GridView contents

        Dim tempQuery As String = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_Suppliers WHERE ENT_SUPPLIER_NBR IS NOT NULL"
        ' Filter ESD Number
        If Len(EsdNumberTextBox.Text) > 0 Then
            tempQuery += " AND ENT_SUPPLIER_NBR " & GetCompareStatement(EsdNumberTextBox.Text, Nothing, EsdNumberDropDownList.SelectedValue)
        End If
        ' Filter Supplier Name
        If Len(SupplierNameTextBox.Text) > 0 Then
            tempQuery += " AND SUP_NAME1 " & GetCompareStatement(SupplierNameTextBox.Text, Nothing, SupplierNameDropDownList.SelectedValue)
        End If
        ' Filter Supplier City
        If Len(SupplierCityTextBox.Text) > 0 Then
            tempQuery += " AND CITY " & GetCompareStatement(SupplierCityTextBox.Text, Nothing, SupplierCityDropDownList.SelectedValue)
        End If
        ' Filter Supplier State
        If Len(SupplierStateTextBox.Text) > 0 Then
            tempQuery += " AND STATE_REGION " & GetCompareStatement(SupplierStateTextBox.Text, Nothing, SupplierStateDropDownList.SelectedValue)
        End If
        ' Filter Active
        If ActiveDropDownList.SelectedIndex > 0 Then
            tempQuery += " AND Active = '" & ActiveDropDownList.SelectedValue & "'"
        End If

        ' Clear user paging/sort
        Session("CurrentPage") = 0
        Session("SortBLOCKED EXPRESSION = Nothing
        GridViewSortDirection = "ASC"

        ' Update current query
        Session("CurrentQuery") = Trim(tempQuery) & " ORDER BY SUP_NAME1 ASC"

        ' Bind GridView to current query
        connection.Open()
        BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
        connection.Close()

    End Sub

   Protected Sub ShowAllButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowAllButton.Click
        ' Show all suppliers

        ' Clear filter options
        EsdNumberDropDownList.SelectedIndex = 0
        SupplierNameDropDownList.SelectedIndex = 0
        SupplierCityDropDownList.SelectedIndex = 0
        SupplierStateDropDownList.SelectedIndex = 0
        ActiveDropDownList.SelectedIndex = 0
        EsdNumberTextBox.Text = ""
        SupplierNameTextBox.Text = ""
        SupplierCityTextBox.Text = ""
        SupplierStateTextBox.Text = ""

        ' Clear user paging/sort
        Session("CurrentPage") = 0
        Session("SortDirection") = Nothing

        ' Update current query
        Session("CurrentQuery") = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_Suppliers WHERE ENT_SUPPLIER_NBR IS NOT NULL ORDER BY SUP_NAME1 ASC"

        ' Bind GridView to current query
        connection.Open()
        BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
        connection.Close()
    End Sub

   Protected Sub SupplierGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SupplierGridView.SelectedIndexChanged
        ' Bind current data
        SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, True)
        SupplierGridView.PageIndex = Session("CurrentPage")
        SupplierGridView.DataBind()

        ' <This is the row the user selected -- do with it what you want>
        supplierNumber.Text = SupplierGridView.SelectedRow.Cells(1).Text
        supplierName.Text = SupplierGridView.SelectedRow.Cells(2).Text
        supplierStreet.Text = SupplierGridView.SelectedRow.Cells(3).Text
      ...


        ' Clear session variables
        Session("CurrentPage") = Nothing
        Session("SortBLOCKED EXPRESSION = Nothing
        Session("CurrentQuery") = Nothing

    End Sub

    Protected Sub SupplierGridView_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SupplierGridView.Sorting
        GridViewSortExpression = e.SortExpression
        Dim pageIndex As Integer = SupplierGridView.PageIndex
        If SupplierGridView.DataSource.GetType().ToString = "System.Data.DataTable" Then
            SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, False)
            SupplierGridView.PageIndex = Session("CurrentPage")
            SupplierGridView.DataBind()
        End If
    End Sub

    Protected Sub SupplierGridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles SupplierGridView.PageIndexChanging
        If SupplierGridView.DataSource.GetType().ToString = "System.Data.DataTable" Then
            SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, True)
            SupplierGridView.PageIndex = e.NewPageIndex
            Session("CurrentPage") = e.NewPageIndex
            SupplierGridView.DataBind()
        End If
    End Sub

 

Hopefully this helps someone out there as much as this forum posting helped me!

 

Mr Blue Coat
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/10/2007 10:51:47 PM

0

For some reason, this forum tool replaced the word "E x p r e s s i o n" with "BLOCKED E X P R E S S I O N" above (remove spaces between letters).

ajrich
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/13/2007 3:48:10 PM

0

Hi, thanks for the post.  Although I was never able to get this working without manually changing the sort direction between postbacks (for some reason it would always stay ascending) I did think of a different approach to this problem that worked for me.

One problem I have with this is that felt so...DataGrid-y.  I disliked the cumbersome work needed for paging and sorting on the 1.0/1.1 DataGrid and was thrilled to see that the GridView dealt with those problem inside of it's "Black Box".  So, after hours trying to get manual sorting things to work in a clean manner I thought maybe I could trick it into thinking my on-the-fly data source is just a standard sortable/pagable datasource (datatable, datagrid or dataview). 

What I did is create a class, as explained in an example on msdn, that has an attribute explaining that the shared method is the Select statement to be used for the object data source.  Here's a snippit of the code I used.

Namespace IB
    ''' <summary>
    ''' Class writen to bind to the object data source.  I need to do this so that I can dynamically change the data based on the filters chosen via the dropdowns
    ''' </summary>
    ''' <remarks></remarks>
    <ComponentModel.DataObject(True)> _
    Public Class FilteredDataManager
        <ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select)> _
        Public Shared Function GetFilteredNewsData() As DataView
            Dim dt As DataTable = Nothing
            
            Try
                Using cm As New Baird.Internet.ContentManagers.CMSNewsContentManager
                    dt = cm.GetNewsData()
                End Using
	'<Custom filtering based on selections on drop downs performed here>
            Catch ex As Exception
                Throw New ApplicationException(String.Format("IB.FilteredDataManager.GetFilteredNewsData: Error {0}{1}", vbCrLf, ex.ToString()))
            End Try

            Return dt
        End Function
    End Class
End Namespace

Now that you have this class you can set this as the source to your ObjectDataSource as so (you can do this in code on even in design mode):   
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False" DataKeyNames="NewsLinkID" AllowSorting="True" HeaderStyle-HorizontalAlign="left" GridLines="none" Width="100%" DataSourceID="ObjectDataSourceNewsData"
<asp:ObjectDataSource ID="ObjectDataSourceNewsData" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetFilteredNewsData" TypeName="UI.News.IB.FilteredDataManager"></asp:ObjectDataSource>
As long as you return a DataSet, DataTable or DataView, the GridView handles sorting and paging automagically - which is how I like it.

Hope this helps someone that has a similar issue as I.

Thanks.
osmanmz
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/25/2007 8:31:18 AM

0

Thanks for the post its helped a great deal.

How is it that your page does an auto postback on sorting or paging.

 I'm using the following code which is very similar,  it does the sorting or paging only when I click a button on the page, not when I sort or page.

 i.e. it is a delayed reaction.  I've also had to add the an invalid postback or call argument error with the suggestion of setting

EnableEventValidation="false" which resolves that issue:

The only difference is that I've using a Master page.

Please have a look at my code below, I've attached the code for the GridView.

Thanks and regards

Mohamed

<%@ Page Language="C#" MasterPageFile="~/ShareX.master" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="BrokerDailyTrade.aspx.cs" Inherits="ShareXIntranet.BrokerDailyTradeForm" %>

<%@ mastertype virtualpath="~/ShareX.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

...

<asp:GridView id="gridViewBrokerDailyTrade" runat="server" AutoGenerateColumns="false" DataKeyNames="ipkBrokerDailyTradeID"

OnSelectedIndexChanged="gridViewBrokerDailyTrade_SelectedIndexChanged" AllowPaging="true" AllowSorting="true"

OnPageIndexChanging="gridViewBrokerDailyTrade_PageIndexChanging" OnSorting="gridViewBrokerDailyTrade_Sorting"

PagerSettings-Mode="NumericFirstLast" PageSize="25"

>

<Columns>

<asp:BoundField ReadOnly="True" DataField="ipkBrokerDailyTradeID" HeaderText="ipkTransactionTradeDetailID" Visible="False"></asp:BoundField>

<asp:BoundField DataField="dtTrade" HeaderText="Trade date" DataFormatString="{0:dd MMM yyyy}" HtmlEncode="False" SortExpression="dtTrade"></asp:BoundField>

<asp:BoundField DataField="dYieldAmount" HeaderText="Yield amount" DataFormatString="{0:C}" HtmlEncode="False" SortExpression="dYieldAmount"></asp:BoundField>

<asp:BoundField DataField="dtYieldAmountPaid" HeaderText="Paid date" DataFormatString="{0:dd MMM yyyy}" HtmlEncode="False" SortExpression="dtYieldAmountPaid"></asp:BoundField>

<asp:ButtonField Text="Select" CommandName="Select" />

</Columns>

<EmptyDataTemplate>

<asp:Label id="lblGridNoData" runat="server" Text="There are no broker daily trades awaiting processing." ForeColor="Red" Font-Bold="True"></asp:Label>

</EmptyDataTemplate>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

<!--<asp:BoundField DataField="exCustom_BrokerName" HeaderText="Broker"></asp:BoundField>-->

186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|


Free Download:




   
  Privacy | Contact Us
All Times Are GMT