Ask a Question related to ASP.NET, Design and Development.

  1. #1

    Default Datagrid sorting

    I have read most messages in regard with this topic, and have tried
    every measure suggested. I'm still haveing problem to get it to work.
    Basically, the page just reloaded as before when I clicked on the
    header link.
    Here is the code :
    ************************************************** **********************
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    Dim lastSortOrder As String
    Dim lastSortColumn As String

    daStaffList.Fill(dsStaffList)

    If Not IsPostBack Then
    ViewState("LastSortOrder") = "ASC"
    ViewState("LastSortColumn") = "LastName"
    dvStaffList.Sort = "LastName" & " " & " ASC"
    daStaffList.Fill(dsStaffList)
    dgStaffList.DataBind()
    End If
    End Sub

    Private Sub dgStaffList_SortCommand(ByVal source As Object, ByVal
    e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
    dgStaffList.SortCommand
    Dim newSortColumn = e.SortExpression.ToString()
    Dim newSortOrder = "ASC" 'Default value
    Dim lastSortColumn = ViewState("LastSortColumn")
    Dim lastSortOrder = ViewState("LastSortOrder")


    If (newSortColumn.Equals(lastSortColumn) And
    lastSortOrder.Equals("ASC")) Then
    newSortOrder = "DESC"
    End If

    ViewState("LastSortOrder") = newSortOrder
    ViewState("LastSortColumn") = newSortColumn

    dvStaffList.Sort = newSortColumn & " " & newSortOrder
    daStaffList.Fill(dsStaffList)
    dgStaffList.DataBind()

    End Sub
    ************************************************** ****************************

    Any help is appreciated

    Simon
    Simon Guest

  2. Similar Questions and Discussions

    1. Sorting in the DataGrid
      It's like this: a column in a DataGrid(u know, the component) receives several numbers from an XML,one for each cell, numbers from 0 to 11. Each nr...
    2. DataGrid Not Sorting
      My web datagrid isn't sorting at all. I have it wired up to a handler, and I know the handler is working (being called), but no sorting. The page...
    3. sorting a datagrid
      In asp.net I have created a datagrid which it data source is determined at runtime. How can add the auto sort functionality to this datagrid? In...
    4. Sorting in a DataGrid with no headings
      I have got a scrollable datagrid within a Div tag and a fixed header created using an HTML table. I would like to be able to sort the datagrid by...
    5. sorting and datagrid and underline
      how to eliminate underline from sorting headers on a datagrid. I modified <A> in the style sheet. Is there any other way to accomplish this in...
  3. #2

    Default RE: Datagrid sorting

    Hi Simon,

    Could you verify that you have the following methods registered under
    InitializeComponent(); ?

    this.dgStaffList.SortCommand += new
    System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.dgStaffList_S
    ortCommand);

    Thanks,
    Blaise Pascal Tine (MSFT)
    --------------------
    >From: [email]wangs@arts.endow.gov[/email] (Simon)
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >Subject: Datagrid sorting
    >Date: 27 Jun 2003 06:59:33 -0700
    >Organization: [url]http://groups.google.com/[/url]
    >Lines: 50
    >Message-ID: <efbfcd95.0306270559.4919dd9d@posting.google.com >
    >NNTP-Posting-Host: 63.169.191.3
    >Content-Type: text/plain; charset=ISO-8859-1
    >Content-Transfer-Encoding: 8bit
    >X-Trace: posting.google.com 1056722373 18471 127.0.0.1 (27 Jun 2003
    13:59:33 GMT)
    >X-Complaints-To: [email]groups-abuse@google.com[/email]
    >NNTP-Posting-Date: 27 Jun 2003 13:59:33 GMT
    >Path:
    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-
    xit-09!supernews.com!postnews1.google.com!not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155429
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >I have read most messages in regard with this topic, and have tried
    >every measure suggested. I'm still haveing problem to get it to work.
    >Basically, the page just reloaded as before when I clicked on the
    >header link.
    >Here is the code :
    >************************************************* ***********************
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    >System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > Dim lastSortOrder As String
    > Dim lastSortColumn As String
    >
    > daStaffList.Fill(dsStaffList)
    >
    > If Not IsPostBack Then
    > ViewState("LastSortOrder") = "ASC"
    > ViewState("LastSortColumn") = "LastName"
    > dvStaffList.Sort = "LastName" & " " & " ASC"
    > daStaffList.Fill(dsStaffList)
    > dgStaffList.DataBind()
    > End If
    > End Sub
    >
    > Private Sub dgStaffList_SortCommand(ByVal source As Object, ByVal
    >e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
    >dgStaffList.SortCommand
    > Dim newSortColumn = e.SortExpression.ToString()
    > Dim newSortOrder = "ASC" 'Default value
    > Dim lastSortColumn = ViewState("LastSortColumn")
    > Dim lastSortOrder = ViewState("LastSortOrder")
    >
    >
    > If (newSortColumn.Equals(lastSortColumn) And
    >lastSortOrder.Equals("ASC")) Then
    > newSortOrder = "DESC"
    > End If
    >
    > ViewState("LastSortOrder") = newSortOrder
    > ViewState("LastSortColumn") = newSortColumn
    >
    > dvStaffList.Sort = newSortColumn & " " & newSortOrder
    > daStaffList.Fill(dsStaffList)
    > dgStaffList.DataBind()
    >
    > End Sub
    >************************************************* **************************
    ***
    >
    >Any help is appreciated
    >
    >Simon
    >
    Blaise Pascal Tine Guest

  4. #3

    Default RE: Datagrid sorting


    No, I don't have that method registered.
    How would I do that ? and where this code goes?
    Thanks


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Simon Wang Guest

  5. #4

    Default Datagrid Sorting

    Hi,

    When trying to dynamically add the header column name in my datagrid I lose
    the sorting abilities.

    private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)

    {

    ListItemType itemType = e.Item.ItemType;

    if (e.Item.ItemType == ListItemType.Header )

    {

    e.Item.Cells[2].Text = "Employee"

    e.Item.Cells[3].Text = "Company Name"

    }

    }

    How can I give it back the sorting ability?



    Thanks,



    Yama


    Yama Guest

  6. #5

    Default Re: Datagrid Sorting

    Yama wrote:
    > Hi,
    >
    > When trying to dynamically add the header column name in my datagrid
    > I lose the sorting abilities.
    >
    > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    >
    > {
    >
    > ListItemType itemType = e.Item.ItemType;
    >
    > if (e.Item.ItemType == ListItemType.Header )
    >
    > {
    >
    > e.Item.Cells[2].Text = "Employee"
    >
    > e.Item.Cells[3].Text = "Company Name"
    >
    > }
    >
    > }
    >
    > How can I give it back the sorting ability?
    Try this to change the header text:

    grd.Columns[2].HeaderText = "Employee";
    grd.Columns[3].HeaderText = "Company Name";

    --

    Jos


    Jos Guest

  7. #6

    Default Re: Datagrid Sorting

    Hello Jos,

    You da man! Thanks that worked.

    Yama




    "Jos" <josnospambranders@fastmail.fm> wrote in message
    news:ezxRFcQgEHA.636@TK2MSFTNGP12.phx.gbl...
    > Yama wrote:
    > > Hi,
    > >
    > > When trying to dynamically add the header column name in my datagrid
    > > I lose the sorting abilities.
    > >
    > > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > ListItemType itemType = e.Item.ItemType;
    > >
    > > if (e.Item.ItemType == ListItemType.Header )
    > >
    > > {
    > >
    > > e.Item.Cells[2].Text = "Employee"
    > >
    > > e.Item.Cells[3].Text = "Company Name"
    > >
    > > }
    > >
    > > }
    > >
    > > How can I give it back the sorting ability?
    >
    > Try this to change the header text:
    >
    > grd.Columns[2].HeaderText = "Employee";
    > grd.Columns[3].HeaderText = "Company Name";
    >
    > --
    >
    > Jos
    >
    >

    Yama Guest

  8. #7

    Default Re: Datagrid Sorting

    Jos,

    Do you happen to know also how I could change the header text of an header
    template:

    <Columns>
    <asp:TemplateColumn HeaderText="Select">
    <HeaderTemplate>
    <asp:checkbox id="chkDeleteAll"
    onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    TextAlign="Left" Text="Select All" ToolTip="Select/Deselect All"
    AutoPostBack="false"></asp:checkbox>
    </HeaderTemplate>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ITEMTEMPLATE>
    <asp:CheckBox id="chkDelete"
    onclick="javascript:HighlightRow(this);" runat="server"
    AutoPostBack="false"></asp:CheckBox>
    </ITEMTEMPLATE>
    </asp:TemplateColumn>
    </Columns>

    How can I change the Text="Select All" dynamically? I am using the resource
    file to globalize my web apps.

    Thanks,

    Yama




    "Jos" <josnospambranders@fastmail.fm> wrote in message
    news:ezxRFcQgEHA.636@TK2MSFTNGP12.phx.gbl...
    > Yama wrote:
    > > Hi,
    > >
    > > When trying to dynamically add the header column name in my datagrid
    > > I lose the sorting abilities.
    > >
    > > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
    > >
    > > {
    > >
    > > ListItemType itemType = e.Item.ItemType;
    > >
    > > if (e.Item.ItemType == ListItemType.Header )
    > >
    > > {
    > >
    > > e.Item.Cells[2].Text = "Employee"
    > >
    > > e.Item.Cells[3].Text = "Company Name"
    > >
    > > }
    > >
    > > }
    > >
    > > How can I give it back the sorting ability?
    >
    > Try this to change the header text:
    >
    > grd.Columns[2].HeaderText = "Employee";
    > grd.Columns[3].HeaderText = "Company Name";
    >
    > --
    >
    > Jos
    >
    >

    Yama Guest

  9. #8

    Default Re: Datagrid Sorting

    Yama wrote:
    > Jos,
    >
    > Do you happen to know also how I could change the header text of an
    > header template:
    >
    > <Columns>
    > <asp:TemplateColumn HeaderText="Select">
    > <HeaderTemplate>
    > <asp:checkbox id="chkDeleteAll"
    > onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    > TextAlign="Left" Text="Select All"
    > ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
    > </HeaderTemplate>
    > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > <ITEMTEMPLATE>
    > <asp:CheckBox id="chkDelete"
    > onclick="javascript:HighlightRow(this);" runat="server"
    > AutoPostBack="false"></asp:CheckBox>
    > </ITEMTEMPLATE>
    > </asp:TemplateColumn>
    > </Columns>
    >
    > How can I change the Text="Select All" dynamically? I am using the
    > resource file to globalize my web apps.
    For this, you can use the ItemDataBound event handler.

    Try:
    (CheckBox)e.Item.FindControl("chkDeleteAll").Text= "new text";

    --

    Jos


    Jos Guest

  10. #9

    Default Re: Datagrid Sorting

    Hi Jos,

    the Text property doesn't exist... Any way to grab it and set it in another
    context?

    I tried the following in the Item DataBound:
    CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
    chk.Text = "New Test";

    But I got an error that the object wasn't referenced...

    Any suggestions?

    Yama



    "Jos" <josnospambranders@fastmail.fm> wrote in message
    news:Ozqe8IWgEHA.380@TK2MSFTNGP10.phx.gbl...
    > Yama wrote:
    > > Jos,
    > >
    > > Do you happen to know also how I could change the header text of an
    > > header template:
    > >
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Select">
    > > <HeaderTemplate>
    > > <asp:checkbox id="chkDeleteAll"
    > > onclick="javascript:SelectAllCheckboxes(this);" runat="server"
    > > TextAlign="Left" Text="Select All"
    > > ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
    > > </HeaderTemplate>
    > > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > > <ITEMTEMPLATE>
    > > <asp:CheckBox id="chkDelete"
    > > onclick="javascript:HighlightRow(this);" runat="server"
    > > AutoPostBack="false"></asp:CheckBox>
    > > </ITEMTEMPLATE>
    > > </asp:TemplateColumn>
    > > </Columns>
    > >
    > > How can I change the Text="Select All" dynamically? I am using the
    > > resource file to globalize my web apps.
    >
    > For this, you can use the ItemDataBound event handler.
    >
    > Try:
    > (CheckBox)e.Item.FindControl("chkDeleteAll").Text= "new text";
    >
    > --
    >
    > Jos
    >
    >

    Yama Guest

  11. #10

    Default Re: Datagrid Sorting

    Yama wrote:
    > Hi Jos,
    >
    > the Text property doesn't exist... Any way to grab it and set it in
    > another context?
    >
    > I tried the following in the Item DataBound:
    > CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
    > chk.Text = "New Test";
    >
    > But I got an error that the object wasn't referenced...
    You're still using the condition:

    if (e.Item.ItemType == ListItemType.Header )

    aren't you?

    --

    Jos


    Jos Guest

  12. #11

    Default Datagrid Sorting

    hi everyone. How do i sort my data grid with my language when user clicks header. My language includes any special char for expamle ?, ?, ?, ?, ?, ?.
    How do i make it?
    hakanh Guest

  13. #12

    Default Re: Datagrid Sorting

    i don't still found any answer
    hakanh Guest

  14. #13

    Default Datagrid Sorting

    I have a datagrid which displays the values from the Dataset. The Dataset
    values are not sorted alphabetically. So the datagrid initially displays the
    values in an unsorted manner. Only when I click on the header of the datagrid
    the values are displayed in assorted manner. I want the datagrid to display the
    values in alphabetical order when it is loaded with the values. Can this be
    done ?
    If so anyone please let me know how to do that .

    srirama.83 Guest

  15. #14

    Default Datagrid Sorting

    I have a datagrid which displays the values from the Dataset. The Dataset
    values are not sorted alphabetically. So the datagrid initially displays the
    values in an unsorted manner. Only when I click on the header of the datagrid
    the values are displayed in assorted manner. I want the datagrid to display the
    values in alphabetical order when it is loaded with the values. Can this be
    done ?
    If so, anyone please let me know how to do that .

    srirama.83 Guest

  16. #15

    Default Datagrid Sorting

    I have a datagrid which displays the values from the Dataset. The Dataset
    values are not sorted alphabetically. So the datagrid initially displays the
    values in an unsorted manner. Only when I click on the header of the datagrid
    the values are displayed in assorted manner. I want the datagrid to display the
    values in alphabetical order when it is loaded with the values. Can this be
    done ?
    If so, anyone please let me know how to do that .

    srirama.83 Guest

  17. #16

    Default RE: Datagrid Sorting

    If you are loading the data into the grid from a database, put an order by in your select with the order you want the grid loaded with.

    ie. Select * from table
    where ...(optional)
    order by column1, column2 etc


    From [url]http://www.developmentnow.com/g/70_2006_12_0_0_867047/Datagrid-Sorting.ht[/url]

    Posted via DevelopmentNow.com Group
    [url]http://www.developmentnow.com[/url]
    KLee Guest

  18. #17

    Default Re: Datagrid Sorting

    sort the dataset prior to loading it into the datagrid.

    Check the help files for dataset.addSort() and dataset.userSort()

    Basically you will use the dataset.addSort()

    dataset.addSort(name,field);
    name = name you want to call this sort
    filed = the field you want to sort on.

    Then you call the dataset.useSort()

    dataset.useSort(name)
    name = what you called the sort in addSort.

    Now your dataset is sorted.



    srirama.83 wrote:
    > I have a datagrid which displays the values from the Dataset. The Dataset
    > values are not sorted alphabetically. So the datagrid initially displays the
    > values in an unsorted manner. Only when I click on the header of the datagrid
    > the values are displayed in assorted manner. I want the datagrid to display the
    > values in alphabetical order when it is loaded with the values. Can this be
    > done ?
    > If so anyone please let me know how to do that .
    >
    Scott Johnson Guest

  19. #18

    Default Re: Datagrid Sorting

    Looks like you want to use the addSort function of the DataSet. So before you
    assign the dataset to the datagrid you would run something like this.

    my_ds.addSort("nameSort", ["name"], DataSetIterator.Descending);

    Later

    Troy

    TroyK Guest

  20. #19

    Default Re: Datagrid Sorting

    Thanks a lot,
    I Used an array as the dataset for datagrid and i used the sortOn() Function of Array.
    And this worked .

    srirama.83 Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139