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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. column selection of GridView

column selection of GridView

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelp
5 Posts 3 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.
  • P Offline
    P Offline
    perreq
    wrote on last edited by
    #1

    Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:

        protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)   
                string s = ((DataRowView)e.Row.DataItem).ToString();
        }
    

    Thanks for help!

    R K 2 Replies Last reply
    0
    • P perreq

      Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:

          protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e)
          {
              if (e.Row.RowType == DataControlRowType.DataRow)   
                  string s = ((DataRowView)e.Row.DataItem).ToString();
          }
      

      Thanks for help!

      R Offline
      R Offline
      Rutvik Dave
      wrote on last edited by
      #2

      I know this is not the perfect solution, but you can apply this until you find another one. Enable Sorting on the gridview and then handle the Sorting event. inside that you will get a e.SortExpression. which is the Column name you clicked on. Now call some method by passing it as parameter and return;. I am not sure but most probably this will work.

      P 1 Reply Last reply
      0
      • P perreq

        Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:

            protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)   
                    string s = ((DataRowView)e.Row.DataItem).ToString();
            }
        

        Thanks for help!

        K Offline
        K Offline
        kadaoui el mehdi
        wrote on last edited by
        #3

        try this: http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/PagingSortingCallbacks.src[^]

        1 Reply Last reply
        0
        • R Rutvik Dave

          I know this is not the perfect solution, but you can apply this until you find another one. Enable Sorting on the gridview and then handle the Sorting event. inside that you will get a e.SortExpression. which is the Column name you clicked on. Now call some method by passing it as parameter and return;. I am not sure but most probably this will work.

          P Offline
          P Offline
          perreq
          wrote on last edited by
          #4

          thanks for the quick reply that seems to be a good approach. I tried implement it but it doesn't invoke the action when i click on the grid. have i forgot something? (I enabled sorting)

          R 1 Reply Last reply
          0
          • P perreq

            thanks for the quick reply that seems to be a good approach. I tried implement it but it doesn't invoke the action when i click on the grid. have i forgot something? (I enabled sorting)

            R Offline
            R Offline
            Rutvik Dave
            wrote on last edited by
            #5

            all you have to do is, AllowSorting = "true" and then handle the "Sorting" event (OnSorting="GridView1_Sorting"). and then click on the column names (it should be appeared as links) at the run time.

            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