Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Gridview Control Edit Mode requires Pressing Edit Button Twice

Posted on 2006-07-16
6
Medium Priority
?
1,604 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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