I have a grid view. When I bind the grid view data from database, all data has to be bound at the time. It is affected to the performance of my application. I am always used index on grid view. So I want that when I clicking each index of grid view, the particular count of data has to return from database. Can any one help for this issue?
What i got from question is that right now you are pulling all the data from a table and binding with the gridview, which of-course is not good and you want to pull only the required amount of data depending on the current page number. Please see the following article for the solution.
ASP.Net Grid View Custom Paging
Related
I have looked-up custom paging with gridviews in ASP.NET, but it seemed to work only for displaying exact same rows from the database to the web page.
In my case, I currently use default gridview paging to select all rows from the database, then process that data in the code behind of my aspx page, and then show custom rows based on that processed data in my gridview.
My question is: I want to know how to select a certain amount of rows from the database that will reflect just enough "custom" rows for 1 page in my gridview on the web page.
Note: I process the data on the front-end and group them in custom rows based on a common, same FKID value.
Would really appreciate the help,
Regards.
Does each FKID-value have the same amount of rows in your table? I assume this isn't the case.
I think your options are the following:
You could leave your logic as-is. If the performance isn't too bad, I think this is the easiest solution.
Create a view at database-level. This view should then directly provide records as you need them as a row in your GridView. This puts the paging-logic at the database-level, and is performance-wise the fastest option I think.
Do the same as option 2, but then at your application level. That could work this way: Construct a select query that gives you the count of distinct FKID values, and a query that can give you a list of FKID values based on a 'startindex' and 'number of rows'. For each FKID returned, fire another query fetching the corresponding rows. Apply your logic, and return the page of rows to your GridView.
I have an ASP.net C# page that uses a stored procedure in a single SQL query to return multiple tables.
I then bind each GridView in the page to the corresponding table from the query:
grdCustomers.DataSource = objDS.Tables[3];
grdCustomers.DataBind();
This works well but clears out the data when you sort the GridView columns. I understand I need to bind the data again on post-back but I'm not sure of an easy way to do this since the GridViews are not bound on page load now.
What's the easiest way to keep the GridView binding on sort as well as sort the columns correctly when binding the data in code behind?
I think it would be easier for you to understand my problem if I explain the scenario a bit.
What I am doing is developing a system to a doctor using asp.net c#. For the creation of the prescription, I add a check box list for the list of medicines and submit button below it. When the submit button clicked selected check box list items added to the sql server database and show a data grid with the selected medicines in the same page.
In the data grid there are two columns for medicine name and dosage.Medicine name is taken from the database.I need to give the user the ability to enter the dosage through that grid view. I need to use update command because the record is already there in the sql server.But empty value in the dosage column.I tried to use update command in the data source control. But I can't figure out how to give the WHERE clause because I can't specify the database row which the updating record relate to.
I would be glad to hear some help from you. All the comments are welcome.
You need to set a parameter(s), please check this example to understand how it works. I guess, that you've added in the database some column that is unique identifier.. some autoincrement int or guid.
I have a grid view that, on selected index, will populate a details view. If the selected index happens to have multiple IP Address's I want to add additional fields to display them. They don't need to be databound since I know the data. I'm using the code below to create the additional template fields. This is done in the Data Binding event.
This works until I select a different row in the grid view, then no data is displayed in the details view. My theory is that it's trying to bind the data but there are a different amount of values returned from the database than controls to put them in. I guess is there an easier way to do this?
// Check for multiple IP
countIP = devicesDetails_CountIP(devicesDataKey);
if (countIP > 1)
{
TemplateField IPAddress2 = new TemplateField();
devicesDetailsView.Fields.Insert(0, IPAddress2);
}
Recently I came across this question, so here is a link that may be of help for future visitors
Create DetailsView from codebehind
I have a form showing a gridview. The data is bound dynamically, depending on several options that the user clicks on. The populating data works fine (bound from dynamically created datasets). The problem lies, when I want to switch between displaying data whereby the tables/datasets contain different layouts. The gridview keeps showing the previous layout.
How would I unbind all data to the gridview, so that I can then display the brand new table?
Thanks.
Set datasource = null ?