I need to click the edit button twice to get the GridView into Edit mode?

Posted on 2012-08-18
Last Modified: 2012-10-05

I created a dataset manually that contains a datatable with rows, columns and data. I used a GridView to display the dataset. (I'm not using a SQLDataSource at all in my application).

Basically this is what I do:

GridView.DataSource = Dataset.Tables.["TestDataTable"];


In the GridView, I used an <asp:BoundField DataFiled="Field1" HeaderText"Field1"> to bound one of the columns in the DataSet to display in the DataGrid. There are other <asp:BoundField> tags for the other columns as well but I'm just trying to give you an idea of how the GridView looks, basic <asp:BoundField> tags.

I set the the GridView.AutoGenerateEditButton = true.

But when I click on the Edit Button, I have to click the Edit Button twice to get into Edit mode and the data is not bound to the Textbox once it is in Edit mode.

I tried to using the GridView_RowEditing event handler to issue the Gridview.Databind() command again but it just make my GridView disappears from the screen.

I plan to use the DataSet as my main DataSource for the DataGrid, any updates, I will do to the DataSet only and not to any database. My application is a stand-alone application that does not connect to a database server. It just collects information and save the information into a programmatically construted DataSet.

So my problem is:

1. Why do I have to click the Edit Button twice to get into Edit Mode and why is the data not being bound to the TextBox once it is in Edit Mode?

2. Why when I issued a GridView.DataBind() command in the GridView_RowEditng event handler, does my Gridview disappears from the screen?


Question by:hanglam
    LVL 20

    Expert Comment

    You sure you have checked the

    if(!isPostBack) before binding the Gridview?

    Author Comment

    Hi informaniac,

    Thanks for the reply, I have check the (!Page.IsPostback)  before binding the GridView.

    Does anyone else have any other suggestions? Any help is appreciated.

    LVL 20

    Accepted Solution

    are you assigning the Datasource in RowEditing event?

    as in

    Gv.DataSource = dt;

    Since you are saying the Gridview disappears after databind in RowEditing, I'm guessing the datasource is getting set to null.

    Author Comment

    Hi informaniac,

    Yes I did that in the RowEditing event,

    GridView.DataSource = Dataset.Table["TestDataTable"];


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 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

    6 Experts available now in Live!

    Get 1:1 Help Now