Solved

Gridview Control Edit Mode requires Pressing Edit Button Twice

Posted on 2006-07-16
6
1,535 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now