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
csharpquestion
21 Posts 5 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.
  • B Offline
    B Offline
    blurMember
    wrote on last edited by
    #1

    I am using c#. i have a gridview and one of the column is Category. I have used the objectdatasource to bind the data. I want to count the number of "P" exist in that column and display it at the footer of the gridview. int presentCount = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //if ( # = "P") presentCount++; } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); } } What whould be the correct way. What syntax should be replaced by #? Is there any sample I can follow?

    thanks in advance. Much appreciated.

    C T 2 Replies Last reply
    0
    • B blurMember

      I am using c#. i have a gridview and one of the column is Category. I have used the objectdatasource to bind the data. I want to count the number of "P" exist in that column and display it at the footer of the gridview. int presentCount = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //if ( # = "P") presentCount++; } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); } } What whould be the correct way. What syntax should be replaced by #? Is there any sample I can follow?

      thanks in advance. Much appreciated.

      C Offline
      C Offline
      coolestCoder
      wrote on last edited by
      #2

      Hi, Please check wether you can write e.Row["Category"] = "P" instead of # = "P". I think this will help !


      "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


      Anant Y. Kulkarni

      B 1 Reply Last reply
      0
      • C coolestCoder

        Hi, Please check wether you can write e.Row["Category"] = "P" instead of # = "P". I think this will help !


        "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


        Anant Y. Kulkarni

        B Offline
        B Offline
        blurMember
        wrote on last edited by
        #3

        There was an error when I compiled. Error Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.GridViewRow' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\

        thanks in advance. Much appreciated.

        C 1 Reply Last reply
        0
        • B blurMember

          There was an error when I compiled. Error Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.GridViewRow' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\

          thanks in advance. Much appreciated.

          C Offline
          C Offline
          coolestCoder
          wrote on last edited by
          #4

          Hi, Sorry about that but i dont know about the GridView. You can use the cells collection of the row - r.Row.Cells(0) where the '0' is column number of your desired column. I am not sure about it but you can atleast try ! check this - http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.cells.aspx[^]


          "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


          Anant Y. Kulkarni

          B 1 Reply Last reply
          0
          • C coolestCoder

            Hi, Sorry about that but i dont know about the GridView. You can use the cells collection of the row - r.Row.Cells(0) where the '0' is column number of your desired column. I am not sure about it but you can atleast try ! check this - http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.tablerow.cells.aspx[^]


            "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


            Anant Y. Kulkarni

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

            Thanks for the link, I have yet to understand. Anyone there who can help? :((

            J 1 Reply Last reply
            0
            • B blurMember

              Thanks for the link, I have yet to understand. Anyone there who can help? :((

              J Offline
              J Offline
              Jay_se
              wrote on last edited by
              #6

              Hi Blur Member .... u may use ," e.Row.Cells[index].Text " to get the value on that Particular Cell ( index th position, zero indexing) of the current row. Hope It works..

              Regards, Jay

              B 1 Reply Last reply
              0
              • J Jay_se

                Hi Blur Member .... u may use ," e.Row.Cells[index].Text " to get the value on that Particular Cell ( index th position, zero indexing) of the current row. Hope It works..

                Regards, Jay

                B Offline
                B Offline
                blurMember
                wrote on last edited by
                #7

                There was an error. Error 1 Cannot implicitly convert type 'string' to 'bool' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\ protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[3].Text = "P") { presentCount++; } } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); }

                thanks for your help so far Jay

                J 1 Reply Last reply
                0
                • B blurMember

                  There was an error. Error 1 Cannot implicitly convert type 'string' to 'bool' C:\WebSites\Attendance\Admin\frm_Report.aspx.cs 322 17 C:\WebSites\Attendance\ protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[3].Text = "P") { presentCount++; } } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); }

                  thanks for your help so far Jay

                  J Offline
                  J Offline
                  Jay_se
                  wrote on last edited by
                  #8

                  if (e.Row.Cells[3].Text == "P") put '==' operator for comparision

                  Regards, Jay

                  B 1 Reply Last reply
                  0
                  • J Jay_se

                    if (e.Row.Cells[3].Text == "P") put '==' operator for comparision

                    Regards, Jay

                    B Offline
                    B Offline
                    blurMember
                    wrote on last edited by
                    #9

                    Basically I have a dropdownlist which filter adminNo and then display each record at the gridview. So user can see how many P exists in column Category for each adminNo. the result display at the footer is 0. i hope it is not due to me filtering records by dropdownlist.

                    jay thanks

                    J 1 Reply Last reply
                    0
                    • B blurMember

                      Basically I have a dropdownlist which filter adminNo and then display each record at the gridview. So user can see how many P exists in column Category for each adminNo. the result display at the footer is 0. i hope it is not due to me filtering records by dropdownlist.

                      jay thanks

                      J Offline
                      J Offline
                      Jay_se
                      wrote on last edited by
                      #10

                      Whether it works or not ? You need to declare the variable 'presentCount' as a 'static' variable inorder to retain its value during the Gridview is population.

                      Regards, Jay

                      B 1 Reply Last reply
                      0
                      • J Jay_se

                        Whether it works or not ? You need to declare the variable 'presentCount' as a 'static' variable inorder to retain its value during the Gridview is population.

                        Regards, Jay

                        B Offline
                        B Offline
                        blurMember
                        wrote on last edited by
                        #11

                        I hope my declaration is correct. public static int presentCount = 0; But yet the footer still show 0. :((

                        JAY THANKS

                        J 1 Reply Last reply
                        0
                        • B blurMember

                          I am using c#. i have a gridview and one of the column is Category. I have used the objectdatasource to bind the data. I want to count the number of "P" exist in that column and display it at the footer of the gridview. int presentCount = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //if ( # = "P") presentCount++; } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = presentCount.ToString(); } } What whould be the correct way. What syntax should be replaced by #? Is there any sample I can follow?

                          thanks in advance. Much appreciated.

                          T Offline
                          T Offline
                          Tiger456
                          wrote on last edited by
                          #12

                          Try out this !.............

                          int presentCount = 0;
                          protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                          {
                          if (e.Row.RowType == DataControlRowType.DataRow)
                          {
                          YourType obj = e.Row.DataItem as YourType;
                          if ( obj.Property = "P")
                          presentCount++;
                          }
                          else if (e.Row.RowType == DataControlRowType.Footer)
                          {
                          e.Row.Cells[3].Text = presentCount.ToString();
                          }
                          }

                          B 1 Reply Last reply
                          0
                          • T Tiger456

                            Try out this !.............

                            int presentCount = 0;
                            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                            {
                            if (e.Row.RowType == DataControlRowType.DataRow)
                            {
                            YourType obj = e.Row.DataItem as YourType;
                            if ( obj.Property = "P")
                            presentCount++;
                            }
                            else if (e.Row.RowType == DataControlRowType.Footer)
                            {
                            e.Row.Cells[3].Text = presentCount.ToString();
                            }
                            }

                            B Offline
                            B Offline
                            blurMember
                            wrote on last edited by
                            #13

                            i am having doubt the data type need to be used. What is the best solution? My Category value is a char data type from the database. :^)

                            thanks in advance. Much appreciated.

                            1 Reply Last reply
                            0
                            • B blurMember

                              I hope my declaration is correct. public static int presentCount = 0; But yet the footer still show 0. :((

                              JAY THANKS

                              J Offline
                              J Offline
                              Jay_se
                              wrote on last edited by
                              #14

                              Believe me it works fine... I think , ur data "P" came from database. It may have some white spaces. use Trim() method to remove that, then the string comparision works properly. Hope it help u... static int count = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string tmp=(e.Row.Cells[3].Text).Trim(); if (tmp == "P") { count += 1; } } if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = count.ToString(); } } -- modified at 6:27 Thursday 17th August, 2006

                              Regards, Jay

                              B 1 Reply Last reply
                              0
                              • J Jay_se

                                Believe me it works fine... I think , ur data "P" came from database. It may have some white spaces. use Trim() method to remove that, then the string comparision works properly. Hope it help u... static int count = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string tmp=(e.Row.Cells[3].Text).Trim(); if (tmp == "P") { count += 1; } } if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = count.ToString(); } } -- modified at 6:27 Thursday 17th August, 2006

                                Regards, Jay

                                B Offline
                                B Offline
                                blurMember
                                wrote on last edited by
                                #15

                                :-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!

                                another brilliant ans from the pro.

                                _ J 2 Replies Last reply
                                0
                                • B blurMember

                                  :-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!

                                  another brilliant ans from the pro.

                                  _ Offline
                                  _ Offline
                                  _AK_
                                  wrote on last edited by
                                  #16

                                  blurMember wrote:

                                  I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!

                                  :laugh:

                                  Best Regards, Apurva Kaushal

                                  1 Reply Last reply
                                  0
                                  • B blurMember

                                    :-D Yes it came from a database. What an awesome solution! Poem for Jay I 1 2 SAY to the person JAY I am so GAY (happy) to finally get the ans... Hip Hip HOORAY!

                                    another brilliant ans from the pro.

                                    J Offline
                                    J Offline
                                    Jay_se
                                    wrote on last edited by
                                    #17

                                    always welcome...:)

                                    Regards, Jay

                                    B 1 Reply Last reply
                                    0
                                    • J Jay_se

                                      always welcome...:)

                                      Regards, Jay

                                      B Offline
                                      B Offline
                                      blurMember
                                      wrote on last edited by
                                      #18

                                      When the user click from the ListBox to view each adminNo, the Show Footer manage to calculate the number of P exist in the gridview. But when the user click another adminNo, the Show Footer number was accumulated with the previous Show Footer. Example: when the user click for the first time Show Footer: 18 second output when user click for the second time, the number of P exist in the gridview is suppose to be 10, but show 38 instead Show Footer: 38

                                      thanks in advance. Much appreciated.

                                      J 1 Reply Last reply
                                      0
                                      • B blurMember

                                        When the user click from the ListBox to view each adminNo, the Show Footer manage to calculate the number of P exist in the gridview. But when the user click another adminNo, the Show Footer number was accumulated with the previous Show Footer. Example: when the user click for the first time Show Footer: 18 second output when user click for the second time, the number of P exist in the gridview is suppose to be 10, but show 38 instead Show Footer: 38

                                        thanks in advance. Much appreciated.

                                        J Offline
                                        J Offline
                                        Jay_se
                                        wrote on last edited by
                                        #19

                                        i think the static variable 'showCount' keeps its old value. So you may declare it properly , in such a way that when u click a item from ur ListBox , the variable is set to zero. hope it helps u

                                        Regards, Jay

                                        B 1 Reply Last reply
                                        0
                                        • J Jay_se

                                          i think the static variable 'showCount' keeps its old value. So you may declare it properly , in such a way that when u click a item from ur ListBox , the variable is set to zero. hope it helps u

                                          Regards, Jay

                                          B Offline
                                          B Offline
                                          blurMember
                                          wrote on last edited by
                                          #20

                                          X| My flu and cough is really bad, i can't even think. :laugh: protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { count = 0; } I did this to save my trouble. Hope no more problem.

                                          thanks again superjay

                                          J 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