insert row to aspxgridview that is not bound to datasource - asp.net

in my webpage i'm using aspxgridview that contains 3 columns with type "text column" and i don't want that gridview to show any retrived data from database so i'm not using datasource
the mission of this gridview is to accept input by user and insert the information entered by user to a table in database
i have set the properties: enableediting and enableinserting to true
the problem is when i run the project and press the hyperlink "new" in the gridview to insert a row in it i can't write any text in the text column and when i press "update" a message appeared that said: "Specified method is not supported."
please note that the property "ReadOnly" in each text column is set to false
i couldn't find example about the use of aspxgridview for insert purpose only without bind it to any datasource
thank u

Why do You need GridView for such functionality? Why not to use simple asp:TextBox with asp:Button for this?
Respond to update:
You can create List of data bound to this page. Bind this list to GridView as datasource.
Render GridView rows in edit mode and fill data to this list. But You will need to handle all gridview events connected to item editing/inserting.
List of Data You can store in ViewState.
Nowadays I would rather go with js implementation of such functionality.
As examples I can provide You with this links:
http://jsfiddle.net/rniemeyer/7RDc3/

Related

How to create and edit gridview at runtime along with adding rows?

I have a aspx page consisting of a calendar button and a textbox.When we click calendar button then a calendar appears and the date which i select on calendar appears in textbox. Now what i want is to load the data from database according to the date selected and allow the user to edit it.And also i want to enable user to add rows at runtime. Do i need to create grid view at runtime?? Can somebody point me in a direction??
You don't need to create the gridview at runtime. You can define the gridview in the markup without having any data initially. You can set the calendar to autopostback and on the server side, capture the new date selected, grab the data based on that date and bind it to your gridview.
As far as editing the data, Gridviews already provide support for this and the amount of code that you need to write largely depends on how the datasource for the gridview is set up. If you use a SQLdatasource with the appropriate settings you practically don't have to write a single line of code besides the markup (Google: Gridview SQLdatasurce editing ASP.net).

New row in ASP.NET GridView Control

I want to do something really simple, I just can't seem to find the EnableClientAddRow property, so I can set it to true. I have a standard GridView control on a web form. I want a button to appear on the web form. When the user clicks the button, an empty row is added to the GridView UI, so the user can enter data in the appropriate fields. The row will of course, have a "Save" button of some type in one of the columns.
I know this functionality must be in the GridView somewhere, I just can't find it. I did find some odd hacks that try to manually implement this. I'm not really interested in footer manipulations or binding tricks, just the standard add row method.
EDIT:
It appears the GridView does not support adding a row as a first-order operation. This appears to be a serious design flaw.
I typically add a new record to the underlying data source as a part of the "add record" button click action. I then re-bind the view in order to show the blank row.
The new record is typically a DataRow if the GridView is bound to a DataTable, or an object if the GridView is bound to a collection of a particular type. Not sure if that is what you consider a binding trick from your question, but it works well and is quite easy to implement.
Edit - more detail to describe the process:
Add the row to the data source, set the EditItemIndex to the newly added row in order for the row to enter edit mode, then bind the data source to the GridView. Your EditItemTemplate would contain a Cancel and a Save button. Cancel would re-bind the GridView to the underlying data source without the empty row and set EditItemIndex to -1, thereby removing the row from the GridView.
How to easily insert row in GridView with SqlDataSource
If you add a new row to the datasource, even if the row has empty values, and you databind the datasource to the Gridview, it should show up as an editable row just like any of the other rows.

datagridview with combobox not displaying data when bound to a Datatable

I have a Datatable that is bound to a DataGridView.The DataGridView gives me the required information retrieved from the DataTable. One of the columns needs to be as a ComboBox. How to I make sure that the information is displayed from the Datatable with one column being a ComboBox?
Please Advice.
Check Using TemplateFields in the GridView Control
Here is another article on Template Fields from MSDN.

Editing a row in a gridview

I have a two text boxes named region id and region name..and a button control
I enter some values into those text boxes and click the button to insert those values into the "gridview"and a "data table" associated with the gridview.
The gridview has the "enable editing" set to true..but when i click the "edit" button of a particular row in a gridview i get no response...i.e i do not get editable textboxes as it happens normally...
What is the solution for this?
You need to set the EditIndex of the row you are editting on the gdvMyGridView_RowEditing event:
gdvMyGridView.EditIndex = e.NewEditIndex
This will display your EditItemTemplate for the relevant row.
GridView Examples for ASP.NET 2.0: Editing the Underlying Data in a GridView
Editable GridView in ASP.NET 2.0
Edit control does not work out of blue. You have to write a backend SQL query for it to implement. The query will most likely look like this.
update regions SET name=#name where ID=#ID
where name and ID are fields of the table. Make sure the ID is the primary key, otherwise update will not work and you won't get any error.

ASP.NET: An editable data bound control in every record?

We need to display the result of an SQL SELECT statement on a ASP.NET 3.5 web page. Although there are a number of columns that need to be displayed, only one of the columns needs an editable text box in it... however every record in the result set needs this editable textbox.
I know I can do this manually by building an html table myself, but I was hoping that there was a way to use a data-bound control (GridView? or ListView?) to do it.
Being somewhat new to ASP.NET, I am hoping there is some one out there who has done this.
--Thanks for your help!
A little further clarification....
We need all records to be editable immediately after display - so all records either need to be displayed in edit mode simultaneously - or the regular display mode needs to have an editable text box in it.
Use a GridView and convert the column that you want to be editable to Template.
In the ItemTemplate of this field, delete the Label and add a text box.
Add an extra "Save" button outside the GridView, and iterate the GridRows, find the text box (in each row), and use it to update the database.
Add a template column and then add a text box control instead of a label control
GridView BoundFields have the ReadOnly property which can be used to prevent the field from being edited in Edit mode. Set it to True for all columns that should not be editable.
<asp:boundfield datafield="myNonEditableColumn" Readonly="true" Headertext="My Non-Editable Column"/>

Resources