Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataGrid in .NET 1.1 C#

DataGrid in .NET 1.1 C#

Scheduled Pinned Locked Moved ASP.NET
csharpcssalgorithmshelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NET4Ever
    wrote on last edited by
    #1

    I have a datagrid with with a button column and a few databound columns. The button column when clicked shows more details for a given row. ex) 123 ABC Company View Records 123 being a unique ID. ABC Company being a description. View Records is the button. When I added sorting to the headers, the application would direct me to the View Records code when clicking on the header to sort. I just wanted to sort. I found the reason. The InitializeComponent() was using an ItemCommand for the View Records button which is executed when any button on the grid is clicked. The headers for sorting were using the SortCommand for a datagrid. When I allowed sorting of the headers, I suspect .NET turned those headers into buttons. Is there anyway around this? I would like to keep my View Records button within the datagrid. I tried changing the View Records button into a hyperlink, but then I got an error for not having a correct datasource for the datagrid. I don't want to mess with the datasource select that is too much change.

    S 1 Reply Last reply
    0
    • N NET4Ever

      I have a datagrid with with a button column and a few databound columns. The button column when clicked shows more details for a given row. ex) 123 ABC Company View Records 123 being a unique ID. ABC Company being a description. View Records is the button. When I added sorting to the headers, the application would direct me to the View Records code when clicking on the header to sort. I just wanted to sort. I found the reason. The InitializeComponent() was using an ItemCommand for the View Records button which is executed when any button on the grid is clicked. The headers for sorting were using the SortCommand for a datagrid. When I allowed sorting of the headers, I suspect .NET turned those headers into buttons. Is there anyway around this? I would like to keep my View Records button within the datagrid. I tried changing the View Records button into a hyperlink, but then I got an error for not having a correct datasource for the datagrid. I don't want to mess with the datasource select that is too much change.

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      In itemcommand event handler add a check on top if arguments.commandName != "sort". Moreover the button columns have the commandname property, so you can set different command name for buttons (if you have multiple buttons in one row) and in itemcommand event handler check the command name and act accordingly.

      -----

      N 1 Reply Last reply
      0
      • S SABhatti

        In itemcommand event handler add a check on top if arguments.commandName != "sort". Moreover the button columns have the commandname property, so you can set different command name for buttons (if you have multiple buttons in one row) and in itemcommand event handler check the command name and act accordingly.

        -----

        N Offline
        N Offline
        NET4Ever
        wrote on last edited by
        #3

        Thanks. However, please bare with me. The headers sorting uses the SortCommand which has a different set of arguments, so I can't use the same itemcommand event handler. ex) ItemCommand Arguments (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) SortCommand Arguments (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) If I were to use ItemCommands arugments to do the if check, I would not have the correct SortCommand arguments to do a sort. If the sortcommand used the same parameters as the itemcommand, I could do the if statement because the sorted headers and buttons would all go to the same event handler.

        S 1 Reply Last reply
        0
        • N NET4Ever

          Thanks. However, please bare with me. The headers sorting uses the SortCommand which has a different set of arguments, so I can't use the same itemcommand event handler. ex) ItemCommand Arguments (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) SortCommand Arguments (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) If I were to use ItemCommands arugments to do the if check, I would not have the correct SortCommand arguments to do a sort. If the sortcommand used the same parameters as the itemcommand, I could do the if statement because the sorted headers and buttons would all go to the same event handler.

          S Offline
          S Offline
          SABhatti
          wrote on last edited by
          #4

          Well surely you will use two event handlers. But if I remember I did face this problem in past, datagrid was firing the itemcommand on sort so I put a check on top in itemcommand event handler if e.commandname <> 'sort' and it worked fine. put a break point on sort and itemcommand event handlers and you will see that sort command is also going to itemcommand event handler.

          -----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups