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