Solved

Gridview Control Edit Mode requires Pressing Edit Button Twice

Posted on 2006-07-16
6
1,579 Views
Last Modified: 2011-10-03
Hi all..

I have a GridView control in an ASP.NET 2.0 page. I added a column that
contains edit, update, cancel buttons. Because I did that, I had to handle
RowEditing event or an exception was thrown.

Well... this is the body of the RowEditing event:

protected void gvParametros_RowEditing(object sender, GridViewEditEventArgs
e)
{
gvParametros.EditIndex = e.NewEditIndex;
}

The fact is that when page is loaded and I click the edit link, page is
refreshed but GridView doesn't enter edit mode. When I press edit link
again, GridView enters edit mode.

any help to solve this behavior would be greatly appreciated
0
Comment
Question by:MSSexpert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:Justin_Case_77
ID: 17119446
rebind the datagrid

protected void gvParametros_RowEditing(object sender, GridViewEditEventArgs
e)
{
gvParametros.DataBind()
gvParametros.EditIndex = e.NewEditIndex;
}
0
 

Author Comment

by:MSSexpert
ID: 17119835
Yes, you'd think that that is how it would work (rebinding).I am a total newbie at C#/ASP.Net BTW so be gentle with me.

I tried as you suggested and it calls "Page_PreRender" and the Gridview disappears from the screen when it exits the Page_PreRender Event. The Page.IsPostBack property is true.


        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        // Editing mode
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.DataBind();
            GridView1.EditIndex = e.NewEditIndex;
        }

        private void BindData()
        {
            GridView1.DataSource = dataExp;

            GridView1.DataMember = "EXPENSE";
            GridView1.DataBind();
        }
       
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17119912
      protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            BindData();

        }
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:MSSexpert
ID: 17128482
I changed the sequeence as suggested to:

      protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            BindData();

        }

No change in result (i.e. Grid still dissapeared)
0
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 17135033
I normally have this below in the page_load event, why is yours in the Page_PreRender? is there any binding in your page load?

           if (!Page.IsPostBack)
            {
                BindData();
            }

if a grid dissapears then the GridView1.DataBind() maybe binding on a empty table -  eg if you debug, put a breakpoint on this line and check it after the the edit is called
GridView1.DataSource = dataExp;    <----- when the edit calls the BindData what value is dataExp, can you also check on debug if this object has any tables with rows...
0
 

Author Comment

by:MSSexpert
ID: 17221736
Thanks for that. The dataexp was being cleared so obviously things were a bit of a mess. I took a deep breath scrapped the entire class and rewrote the code and it worked first time. Thanks Again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question