how to insert row in grid view - c#

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.

Related

Asp.net: alternative for gridview + horizontal accordion that display a table?

I need to make a table with huge data from a database, I've done it very easy with a gridview in asp.net but there is a big problem,I need to customize that table a lot.
I want something like this, with a row with data about a person and the row after with a description of projects he's in, then another row with another person data and so on.
Table:
https://ibb.co/dJmEqw
And when i click/hover on a platform(platform i want to be a accordion propriety/it can be a button too) to display a table in the right or down side.
Table inside the platform's accordion:
Hope you get the idea guys, how can I do this with horizontal table lines, tables in accordions click/hover and databind? I need to take data from database and put it in the tables I described but I don't know if i can do that with asp.net gridviews which automatically generate the rows/columns it needs or is it another method ?
Any idea, advice, code is welcome, thanks!
A GridView is a simple "PowerPoint" solution for simple data models.
If you want more complex things get rid of the GridView and use a Repeater to create your HTML table instead. The Repeater control lets you create the table row tags in the ItemTemplate. You can easily generate two rows for each item in DataSource.
Of course, you need to generate the table cells (columns) manually as well with the Repeater control. Use Literal or Label controls to view the data in the table cells. Use
<%#: DataBinder.Eval(Container.DataItem, "propertyname") %>
to assign the Text properties of the controls.

How get a new datatable after reordering the gridview

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

How to edit the GridView and Update values if the GridView is user defined

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.

GridView How to update a value of current editing row with a new one?

-Simple gridview and sql data source to bind the data info to gridview.
On row updating how can I update a certain cell of current editing row with a new value set by me?
Thanks
If you are doing this in visual studio you can use the graphical interface to change properities to both gridview and sql datasource and configure this without writing code.
Take a look at this if you want to see how it's done in asp:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx
What really happens is that it updates the whole row in database, and displays the new values. This means that you don't need to change value in just one cell, but rather the whole row

Insert/Update values in a gridview

What would be the best way to Insert/Update the values in a Grid view
on clicking a save button placed somewhere.
in the page .
I dont want that to be done like Using Insert Item template and EditItemTemplate.
My thought:
"Loop through each row of Gridview and
connecting to database and
execute the command
and close the connection."
Or is there any way so that we can connect to database only once and perform
Insert/Update operations.
any suggestions would be appreciated..
Thanks in advance.
May these articles help you:
Bulk Edit with GridView
Edit Update Multiple Records/Rows In Gridview With Checkbox ASP.NET
There are many other related articles:
Editable GridView in ASP.NET 2.0
ASP.NET GridView - Add a new record
Insert, Update, Delete with Gridview....simple way

Categories

Resources