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. Count number of records from a tabel and display result in a gridview column at run time.

Count number of records from a tabel and display result in a gridview column at run time.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorialquestion
3 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.
  • E Offline
    E Offline
    Eagle32
    wrote on last edited by
    #1

    Hi I am using a gridview to display data from my table at runtime. I am new to ASP.NET. I am not using boundfields but I am using Template fields. I specify the HeaderText and DataKeys I am using a web service to provide me a DataSet of the chosen table and bind it to the GridView in page_load event. I would like to count the number of records from a chosen table and display that in the Gridview. I have written a method to return number of records by passing in a string parameter product name but i am not sure of how to invoke the method so the value is shown in the GridView. How could i go about doing this? Do i need to invoke the method using Eval like this:

    <asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">
    <ItemTemplate>
    <%#GetRowCount(Eval(ProductName))%>
    </ItemTemplate>
    </asp:TemplateField>

    Would the above work? Thanks,

    S 1 Reply Last reply
    0
    • E Eagle32

      Hi I am using a gridview to display data from my table at runtime. I am new to ASP.NET. I am not using boundfields but I am using Template fields. I specify the HeaderText and DataKeys I am using a web service to provide me a DataSet of the chosen table and bind it to the GridView in page_load event. I would like to count the number of records from a chosen table and display that in the Gridview. I have written a method to return number of records by passing in a string parameter product name but i am not sure of how to invoke the method so the value is shown in the GridView. How could i go about doing this? Do i need to invoke the method using Eval like this:

      <asp:TemplateField HeaderText="ProductName" SortExpression="ProductName">
      <ItemTemplate>
      <%#GetRowCount(Eval(ProductName))%>
      </ItemTemplate>
      </asp:TemplateField>

      Would the above work? Thanks,

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      Why to hit performance(and extra code!) so much when you can get the same information in the dataset of gridview along with other data? Using webservice when you are getting data, also retrieve the count of rows in it. Or, if you cannot do that, then before using it as a source to grid, append the count of rows to dataset and use the modified dataset as datasource of your grid. You are all set!

      E 1 Reply Last reply
      0
      • S Sandeep Mewara

        Why to hit performance(and extra code!) so much when you can get the same information in the dataset of gridview along with other data? Using webservice when you are getting data, also retrieve the count of rows in it. Or, if you cannot do that, then before using it as a source to grid, append the count of rows to dataset and use the modified dataset as datasource of your grid. You are all set!

        E Offline
        E Offline
        Eagle32
        wrote on last edited by
        #3

        Can you provide me an example please if you dont mind? Thanks,

        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