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. gridview

gridview

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
11 Posts 7 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.
  • K Offline
    K Offline
    Kissy16
    wrote on last edited by
    #1

    hai all, i have a sqlstatemnt which returns 10 rows. I am fillig this data in gridview using datareader.Nothing new. But i wanted to fill the data on some condition,so that the rows which are fulfilling that condition can only come in the gridview. out of 10 rows i need 2,5,7,9,10 rows data.Infact i want to skip the data on some condition. I s possible with datareader? if yes how to do?If not how to do? Please anybody have any idea is helpful for me. Thanks in advance.

    kissy

    A A O L 4 Replies Last reply
    0
    • K Kissy16

      hai all, i have a sqlstatemnt which returns 10 rows. I am fillig this data in gridview using datareader.Nothing new. But i wanted to fill the data on some condition,so that the rows which are fulfilling that condition can only come in the gridview. out of 10 rows i need 2,5,7,9,10 rows data.Infact i want to skip the data on some condition. I s possible with datareader? if yes how to do?If not how to do? Please anybody have any idea is helpful for me. Thanks in advance.

      kissy

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      I dont know why do you need to use DataReader. Of course you can do that, just need a counter while you read each datarow from the datareader. Otherwise, I would suggest to get a DataTable from the sqlStatement and use LINQ or by any means to filter out those rows.

      datatable.AsEnumerable().Where(datarow=>{
      // your logic
      });

      Something like this . :thumbsup:

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      Visit My Website-->**

      www.abhisheksur.com

      1 Reply Last reply
      0
      • K Kissy16

        hai all, i have a sqlstatemnt which returns 10 rows. I am fillig this data in gridview using datareader.Nothing new. But i wanted to fill the data on some condition,so that the rows which are fulfilling that condition can only come in the gridview. out of 10 rows i need 2,5,7,9,10 rows data.Infact i want to skip the data on some condition. I s possible with datareader? if yes how to do?If not how to do? Please anybody have any idea is helpful for me. Thanks in advance.

        kissy

        A Offline
        A Offline
        Anurag Gandhi
        wrote on last edited by
        #3

        If your datasource is a collection object, then you can use linq to filter the data source and bind the result with the GridView. Else, you can filter your data in RowDataBound event,

        if(condition)
        e.Row.Visible = false;

        hope this will help.

        Anurag Gandhi.
        http://www.gandhisoft.com
        Life is a computer program and every one is the programmer of his own life.

        K 1 Reply Last reply
        0
        • A Anurag Gandhi

          If your datasource is a collection object, then you can use linq to filter the data source and bind the result with the GridView. Else, you can filter your data in RowDataBound event,

          if(condition)
          e.Row.Visible = false;

          hope this will help.

          Anurag Gandhi.
          http://www.gandhisoft.com
          Life is a computer program and every one is the programmer of his own life.

          K Offline
          K Offline
          Kissy16
          wrote on last edited by
          #4

          I have given the following code,but still it is displaying all the rows. If e.Row.Cells(2).Text <> "" Then If ((e.Row.Cells(2).Text = e.Row.Cells(2).Text) + 1) Then e.Row.Visible = False End If End If

          kissy

          B A 2 Replies Last reply
          0
          • K Kissy16

            I have given the following code,but still it is displaying all the rows. If e.Row.Cells(2).Text <> "" Then If ((e.Row.Cells(2).Text = e.Row.Cells(2).Text) + 1) Then e.Row.Visible = False End If End If

            kissy

            B Offline
            B Offline
            Brij
            wrote on last edited by
            #5

            try to debug your code you will find the exact problem.

            Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0

            1 Reply Last reply
            0
            • K Kissy16

              hai all, i have a sqlstatemnt which returns 10 rows. I am fillig this data in gridview using datareader.Nothing new. But i wanted to fill the data on some condition,so that the rows which are fulfilling that condition can only come in the gridview. out of 10 rows i need 2,5,7,9,10 rows data.Infact i want to skip the data on some condition. I s possible with datareader? if yes how to do?If not how to do? Please anybody have any idea is helpful for me. Thanks in advance.

              kissy

              O Offline
              O Offline
              overtech06
              wrote on last edited by
              #6

              Normally you would build that condition into your SQL query statement so that the query only returns those rows you want included in the gridview. - Dave

              K 1 Reply Last reply
              0
              • K Kissy16

                I have given the following code,but still it is displaying all the rows. If e.Row.Cells(2).Text <> "" Then If ((e.Row.Cells(2).Text = e.Row.Cells(2).Text) + 1) Then e.Row.Visible = False End If End If

                kissy

                A Offline
                A Offline
                Abhijit Jana
                wrote on last edited by
                #7

                Kissy16 wrote:

                If ((e.Row.Cells(2).Text = e.Row.Cells(2).Text) + 1) Then

                Check this line !! :rolleyes:

                Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                1 Reply Last reply
                0
                • K Kissy16

                  hai all, i have a sqlstatemnt which returns 10 rows. I am fillig this data in gridview using datareader.Nothing new. But i wanted to fill the data on some condition,so that the rows which are fulfilling that condition can only come in the gridview. out of 10 rows i need 2,5,7,9,10 rows data.Infact i want to skip the data on some condition. I s possible with datareader? if yes how to do?If not how to do? Please anybody have any idea is helpful for me. Thanks in advance.

                  kissy

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  you nedd to create tp class one will contain the object of other claoss

                  ClientBasePlanData

                  ClientBasePlanList : List<ClientBasePlanData>

                  create the object of ClientBasePlanData fill it and add it into ClientBasePlanList

                  and later bind it

                  K 1 Reply Last reply
                  0
                  • L Lost User

                    you nedd to create tp class one will contain the object of other claoss

                    ClientBasePlanData

                    ClientBasePlanList : List<ClientBasePlanData>

                    create the object of ClientBasePlanData fill it and add it into ClientBasePlanList

                    and later bind it

                    K Offline
                    K Offline
                    Kissy16
                    wrote on last edited by
                    #9

                    i could not understand what u r saying. I can't give any condition in my sqlquery so that only desired records can come. From the display only i have to do,i never done the thing u r telling. can u give some other idea please?

                    kissy

                    1 Reply Last reply
                    0
                    • O overtech06

                      Normally you would build that condition into your SQL query statement so that the query only returns those rows you want included in the gridview. - Dave

                      K Offline
                      K Offline
                      Kissy16
                      wrote on last edited by
                      #10

                      I can't give any condition in my sqlquery so that only desired records can come. From the display only i have to do,can u give something with gridview which can fulfill my requirement ?

                      kissy

                      O 1 Reply Last reply
                      0
                      • K Kissy16

                        I can't give any condition in my sqlquery so that only desired records can come. From the display only i have to do,can u give something with gridview which can fulfill my requirement ?

                        kissy

                        O Offline
                        O Offline
                        overtech06
                        wrote on last edited by
                        #11

                        Instead of binding the SQL command with the gridview, store the results of the SQL query that match your criteria in a dataset. Then bind the dataset with the gridview. I think this is what Abhishek was suggesting as well. It would look something like:

                        // Create a dataset that represents the data you are retrieving from the database
                        DataSet myDataSet = new DataSet();
                        DataTable myDataTable = myDataTable.Tables.Add();
                        myDataTable.Columns.Add("ID", typeof(int));
                        myDataTable.Columns.Add("Foo", typeof(string));
                        myDataTable.Columns.Add("Bar", typeof(string));

                        // Execute your sql reader as normal
                        connection.Open();
                        SqlDataReader dr = cmd.ExecuteReader();
                        while(dr.Read())
                        {
                        // instead of binding the reader, add the records you want to the dataset
                        if (dr["myCriteria"].ToString() == "this")
                        {
                        myDataTable.Rows.Add(
                        (int)dr["ID"],
                        dr["Foo"].ToString(),
                        dr["Bar"].ToString()
                        );
                        }
                        }
                        dr.Close();
                        connection.Close();

                        // Now bind the dataset you created to your GridView
                        myGridView.DataSource = myDataSet;
                        myGridView.BindData();

                        This could be done more elegantly by using myDataTable.Load(dr) then removing the rows that do not meet your criteria via a LINQ statement. But it should give you an idea of what you are trying to accomplish with a DataSet and get you started... - Dave

                        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