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. Data Grid filtering

Data Grid filtering

Scheduled Pinned Locked Moved ASP.NET
questioncsharpcssasp-net
6 Posts 4 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.
  • G Offline
    G Offline
    GaryT80
    wrote on last edited by
    #1

    I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT

    R J 2 Replies Last reply
    0
    • G GaryT80

      I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT

      R Offline
      R Offline
      Rakheesh Chalil
      wrote on last edited by
      #2

      If you want to disply only a particular user's items only in the datagrid, you will have to create a different datasource for that. For example, if you are using dataset or datatable as datasource, you will have to create a dataview and filter the particular user id. Then bind the datagrid with the dataview as datasource hope this will help

      1 Reply Last reply
      0
      • G GaryT80

        I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT

        J Offline
        J Offline
        JoinTTT
        wrote on last edited by
        #3

        Hi, Firstly You must have a dataset on your hand code behind. You can write a method like this, protected void Page_Load(object sender, EventArgs e) { if{!IsPostBack} { querystring = "Your query"; GetData(String queryString); yourdatagrid.DataBind; } } DataSet GetData(String queryString) { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(queryString, SqlConnection); adapter.Fill(ds); return ds; } I hope I understand you correctly.

        G 1 Reply Last reply
        0
        • J JoinTTT

          Hi, Firstly You must have a dataset on your hand code behind. You can write a method like this, protected void Page_Load(object sender, EventArgs e) { if{!IsPostBack} { querystring = "Your query"; GetData(String queryString); yourdatagrid.DataBind; } } DataSet GetData(String queryString) { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(queryString, SqlConnection); adapter.Fill(ds); return ds; } I hope I understand you correctly.

          G Offline
          G Offline
          GaryT80
          wrote on last edited by
          #4

          Well let me see if I can explain a little better. I want to somehow take the current users login name and filter a table with that string. GT

          J R 2 Replies Last reply
          0
          • G GaryT80

            Well let me see if I can explain a little better. I want to somehow take the current users login name and filter a table with that string. GT

            J Offline
            J Offline
            JoinTTT
            wrote on last edited by
            #5

            Yourdatasource.Filter = "User = " + Session["LoginName"].ToString; My last answer! :)

            1 Reply Last reply
            0
            • G GaryT80

              Well let me see if I can explain a little better. I want to somehow take the current users login name and filter a table with that string. GT

              R Offline
              R Offline
              RichardGrimmer
              wrote on last edited by
              #6

              The grids expose a RowFilter property, which can be set to something like

              myGrid.RowFilter = "UserName=" + userNameToFilterBy;
              myGrid.DataBind();

              "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

              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