I populate a gridview from the db.
then i re arranged the rows in the gridview with javascript code.
i want to copy the rearranged gridview to a datatable
how it possible??
If you re-arranged your data using Javascript, you will have to update the database using Javascript. You will not be able to do if using server-side code.
Getting data and binding a GridView on the server-side and then rearranging it with Javascript is not a good idea. I suggest you either get your data purely from Javascript, or arrange your data on the server side before binding your GridView.
There could be multiple methods
First method
GridView row would have a hidden field in each row which should be updated with new row index and have a column for row index / order in database.
When user changes the row index of GridView Row, you will have to change the hidden fields of all effected with new rowindex. On server side you will have to iterate through the GridView rows and save the respective rows index / order in row column for order of row.
Second Method
You can send the changed rows index on each arrangement using the ajax (jquery ajax) and save the changed index in database row order column.
if you need to sort the gridview without reloading the page , then use an update panel enable and code for gridview pageindexchanging and sorting event , if you need any indication while processing use an updateprogress control .
If you are intended to update the data . then use ajax to send the data to a webmethod and update it into DB
Related
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 don't know think I wrote any code for this since the properties are all default. I don't want the user to have to add those by themselves when it is in the middle of the run.
It lets me add in columns but not rows in the designer.
Is there any property that can start the program with more than 1 row in the data grid view?
Populating the grid with data must be done with code. If you populate the grid in the Load event handler then the user will see that data when the form is displayed. You can add data directly to the grid or you can populate a DataTable or some other list and bind that to the grid.
If you're saying that you actually want multiple blank rows in the grid then you need to add those rows. The row you see by default is not actually part of the data of the grid. It's just there to indicate to the user that they can enter data.
I have a GridView which is completely user defined. The first column of the GridView is from the ListBox1. The headers are defined using ListBox2.
There fore I need to update rows of the GridView with some integer value and make sure the Gridview holds that value until a button is clicked.
Once the button is clicked I want to read each columns of the GridView that has values entered and create a table in the database with the headers names as columns and just replicate the GridView as table in database.
I have attached a screenshot of my GridView. Kindly help me fix this problem.
There are 2 key things to implement UPDATE logic in a GridView
In the GridView markup, you have to add an eventhandler for OnRowUpdating event
<asp:GridView ID="XXX" runat="Server" .....
OnRowUpdating="UpdateRecord" ..........>
Then you need to implement this "UpdateRecord" method referred above with your custom code which will basically retrieve the data from the grid row and update it to your datasource
You can refer to some sample code of how this can be achieved here
To point out again, in your case, since you want to dynamically create the table as well, you will need to additionally do that as well. Personally, i have no clue why you would go with such a design but in absence of any information, i assume you know best.
I have a custom gridview on rowdatabound i am adding new gridviewrows . but on postback the data in newly added row is not persists. Please help me to maintain the state of grid on postback as well...Actually i m showing group header rows and footer rows and showing some calculated values in group footer row...but on post back the values of new group rows is not persists but the grid row is ther without values.
You're adding the rows dynamically so you have to populate the grid every time the page is posted back, not just if(!this.IsPostBack).
If you're not persisting to a db every post-back and generating the grid looping through some result-set coming from your db - you might have to store info about the temporary rows in ViewState. People will be able to help on this if you expand your question.
If you're populating dynamically and the data is coming straight from some db (or even State) every post-back you might wanna disable the grid viewstate (as in that case you're sending back and forth useless stuff).
i want to insert a new row to grid view while i click new button with out using the sqldatasource. and also how to edit, update, and delete rows from grid view. pls help me
[visual studio 2008
asp.net with c#]
thanks
thiru
What do you mean by "without using the SqlDataSource" ? How do you intend to propagate the inserted data to the data store, then ? You have not specified what other method you are using.
Anyway, the GridView does not inherently support insertion of records, but you can accomplish it by creating a FooterTemplate in which you create the fields for entry of new data. Additionally, provide a column to allow for Insert/Cancel buttons in the FooterTemplate.
Here's a good sample: How to easily insert row in GridView with SqlDataSource
Good gridview tutorial : ASP.NET Quickstart Tutorials
For adding new row you could try putting controls in footer row of the GridView.
Editing, updating and deleting require you to do two things:
implement those operations in the SqlDataSource
enable these operations in GridView
If you want to do it without the SQL datasource, then set DataTable as a GridView's datasource.
Good example on how to populate and add a row to datatable.