Solved

Gridview Control Edit Mode requires Pressing Edit Button Twice

Posted on 2006-07-16
6
1,590 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
Technology Partners: 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!

 

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

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.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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