c#.net datagrid sorting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaitanya02
    New Member
    • May 2007
    • 46

    c#.net datagrid sorting

    Hi,
    I am new to C#.net and am in the learning curve.
    I designed a c#.net data grid that connects to my local DB server to display the table data.

    I want to enable sorting to this data grid by one particular column name, could anyone help me in this regard please. Let em know if there are any questions that I can provide answers to.

    Thanks,
    Tanya
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do you want it allowed on ONLY one column, or on all of them?
    What version of .NET are you using? (Determines if you can use DataGridView or not)

    Comment

    • chaitanya02
      New Member
      • May 2007
      • 46

      #3
      Originally posted by Plater
      Do you want it allowed on ONLY one column, or on all of them?
      What version of .NET are you using? (Determines if you can use DataGridView or not)

      ----------------

      Thanks for the prompt reply.

      Answer is Yes, I just want to sort the data grid with just one column in the grid.
      Dotnet version: 2.0.

      Sorting the grid insense, say for ex: the column names are status,severity ,name.
      I want to sort the data grid by the status. If I select the status as open /close the grid should display values accordingly.

      Does this answer your question?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Maybe, be default (I think) when using the DataGridView object (which you should be using) all the columns can be sorted ascending/descending just by clicking on their name.
        I think you can over-ride this ability and cancel any clicks on the columns you don't want.

        Check the SortMode property on Columns (and ColumnSortModeC hanged event on the DataGridView) to get you started.

        Comment

        • chaitanya02
          New Member
          • May 2007
          • 46

          #5
          Originally posted by Plater
          Maybe, be default (I think) when using the DataGridView object (which you should be using) all the columns can be sorted ascending/descending just by clicking on their name.
          I think you can over-ride this ability and cancel any clicks on the columns you don't want.
          =====

          I am sorry, I think I didnt follow what you said completely. Is there any property I can set to enable this sorting ascending/descending order? I actually set the
          enable pagesorting/paging callbacks to true in the grid view properties. But unable to see the changes on the browser. Do I have to do something on the code behind as well?

          Thanks,
          Tanya

          Comment

          • chaitanya02
            New Member
            • May 2007
            • 46

            #6
            Originally posted by chaitanya02
            =====

            I am sorry, I think I didnt follow what you said completely. Is there any property I can set to enable this sorting ascending/descending order? I actually set the
            enable pagesorting/paging callbacks to true in the grid view properties. But unable to see the changes on the browser. Do I have to do something on the code behind as well?

            Thanks,
            Tanya
            =============== ============

            can someone help me in this, please!

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Ah ha!
              You're doing a web application, so the object is GridView, I think that actually makes it easier.
              Turn on the column sorting, then attach a handler to the sort event. Then if the column is not the one you want to be allowed to sort on, descard the event and don't perform the sort.
              There is probably something you could do in the rowdatabound event that will keep all the columns in the header row from showing clickable links too.

              Comment

              Working...