Why Can't I Edit My GridView?

J

Joey

asp.net 2.0
VS2005
C#

In my web app I added a gridview and then manually configured
boundcolumns, for an in-session dataset to act as a datasource. Then I
added an Edit commandfield. When I run the page, in each row in the
gridview I see the data and the Edit and Delete links just fine. But
when I click an edit link, the post posts back and nothing else
happens...I do not get textboxes/checkboxes for the columns in the
grid. Each of these columns has its ReadOnly property set to False, so
what's going on here?

JP
 
J

Joey

asp.net 2.0
VS2005
C#

In my web app I added a gridview and then manually configured
boundcolumns, for an in-session dataset to act as a datasource. Then I
added an Edit commandfield. When I run the page, in each row in the
gridview I see the data and the Edit and Delete links just fine. But
when I click an edit link, the post posts back and nothing else
happens...I do not get textboxes/checkboxes for the columns in the
grid. Each of these columns has its ReadOnly property set to False, so
what's going on here?

JP

Okay, I am getting frustrated because all the examples seem to show
how to do this with SqlDataSource or ObjectDataSource controls.

I simply have a dataset maintained in session state. When the page
loads, I bind the gridview to it and show the data. When I add to it,
I do an insert on the dataset and then rebind. When I delete, I handle
the grids RowDeleting event, remove the row from the dataset and then
rebind. This is the same way I did it in .net 1.1. It worked then and
it works now in 2.0. But for edits...

When I click the Edit link in any row in the grid, a postback occurs
and then nothing else happens. Nothing, no textboxes, no changeover of
the Edit links to Update and Cancel, etc...

If I handle the grids RowEditing event and then use
this.grdMyGrid.EditIndex = e.NewItemIndex.

The textboxes will appear, but then only after the SECOND time I click
Edit.

Does anyone know what is causing this?
 
J

Joey

Okay, I am getting frustrated because all the examples seem to show
how to do this with SqlDataSource or ObjectDataSource controls.

I simply have a dataset maintained in session state. When the page
loads, I bind the gridview to it and show the data. When I add to it,
I do an insert on the dataset and then rebind. When I delete, I handle
the grids RowDeleting event, remove the row from the dataset and then
rebind. This is the same way I did it in .net 1.1. It worked then and
it works now in 2.0. But for edits...

When I click the Edit link in any row in the grid, a postback occurs
and then nothing else happens. Nothing, no textboxes, no changeover of
the Edit links to Update and Cancel, etc...

If I handle the grids RowEditing event and then use
this.grdMyGrid.EditIndex = e.NewItemIndex.

The textboxes will appear, but then only after the SECOND time I click
Edit.

Does anyone know what is causing this?

Finally got it...

http://www.dotnetbips.com/articles/66852121-52f5-40b4-a077-eb464fa1b339.aspx

Thanks, Bipin!
 
P

Phil H

Okay, I am getting frustrated because all the examples seem to show
how to do this with SqlDataSource or ObjectDataSource controls.

I simply have a dataset maintained in session state. When the page
loads, I bind the gridview to it and show the data. When I add to it,
I do an insert on the dataset and then rebind. When I delete, I handle
the grids RowDeleting event, remove the row from the dataset and then
rebind. This is the same way I did it in .net 1.1. It worked then and
it works now in 2.0. But for edits...

Hi Joey

It may be that a Dataset as a datasource is not supported by automatic
databinding and mode changes like with the other types of datasource
you mention. If your source is a dataset then you need to create an
ObjectDataSource (i.e. add class file to your App_Code directory) and
place the code for maintaining it in there. Create some public
functions and methods that retrieve, update and insert data. Then add
an ObjectDatasource to your page and you will be able to configure the
select, insert, update and delete commands to link to them. Finally
link your Gridview to the ObjectDataSource and it will behave as
normal (you'll need to convert the columns to templates and manually
type in Eval("columnName") or Bind("ColumnName") for the databindings.
When I click the Edit link in any row in the grid, a postback occurs
and then nothing else happens. Nothing, no textboxes, no changeover of
the Edit links to Update and Cancel, etc...

If I handle the grids RowEditing event and then use
this.grdMyGrid.EditIndex = e.NewItemIndex.

The textboxes will appear, but then only after the SECOND time I click
Edit.

Does anyone know what is causing this?

That's because you have to re-execute Databind before the change to
EditIndex takes effect. It occurs automatically after the subsequest
postback hence the delay.

HTH

Phil Hall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top