Help with GridView

M

Maqsood Ahmed

Hello,
I am new to ASP.net 2.0. I have successfully bound a in-memory DataTable
(not connected with a database) with GridView. I have set
AutoGenerateEditButton property to true. Now whenever i click on Edit
link, the page does postback, but the row does not become editable. I
have also tried
GridView1.Rows[e.NewEditIndex].RowState = DataControlRowState.Edit;
in RowEditing event handler. Is it something which I am missing.
Thanks in advance.

Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 
T

Teemu Keiski

Hi,

if you do binding in code make sure that

a) You bind it in Page_Load inside "If Not Page.IsPostBack Then" check

b) you indeed change the index in RowEditing, and then bind the grid again
 
M

Maqsood Ahmed

Hell Teemu,
Thanks for your reply.
I am already checked IsPostBack property in Page_Load event handler.
Also I have not changed the index in the RowEditing event. The row
editing event handler looks like this::
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs
e)
{
GridView1.Rows[e.NewEditIndex].RowState =
DataControlRowState.Edit;
}

Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 
T

Teemu Keiski

What if you do:

GridView1.EditIndex = e.NewEditIndex;

and then *do the binding of the grid again* as you do initially in
Page_Load.
 
N

Neutrino

Because the web is still a "stateless" medium, the problem might be
that the DataTable object is being destructed and re-created on each
round trip (postback) and so the DataBinding call is reseting
everything in your GridView. I beleive that for this to work the
DataTable object must be persisted (perhaps in the Session State or the
ViewState). The GridView is already persisted by the View State and
Control State.

Hope this helps.
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top