Link to home
Start Free TrialLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

gridview - rowCancelingEdit

I have a simple gridview that is used to edit some records.  When I cancel the edit from the gridview, I have to click the "cancel" button twice??  

Why doesn't the edit mode close when the cancel button is clicked once?

Any help is appreciated.
Thank you.


<asp:GridView 
            ID="GridView1"
            AutoGenerateColumns="False" 
            runat="server" 
            OnRowEditing="GridView1_RowEditing" 
            OnRowCancelingEdit="GridView1_RowCancelingEdit" 
            Width="750px" 
            OnRowUpdating="GridView1_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="Description">
                    <ItemTemplate>
                        <asp:Label ID="lblDescription" Text='<%# Eval("description") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtDescription" Text='<%# Eval("description") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ControlStyle Width="300px" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle Width="300px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Metric">
                    <ItemTemplate>
                        <asp:Label ID="lblMetric" Text='<%# Eval("metric") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtMetric" Text='<%# Eval("metric") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <ControlStyle Width="300px" />
                    <HeaderStyle HorizontalAlign="Left" />
                    <ItemStyle Width="300px" />
                </asp:TemplateField>
                <asp:CommandField 
                    ButtonType="Button" 
                    ShowEditButton="True" >
                    <ControlStyle Width="150px" />
                    <ItemStyle Width="150px" />
                </asp:CommandField>
            </Columns>
        </asp:GridView>
 
public partial class CustomerServiceMetricsManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSource = CustomerServiceMetricsDAO.GetCustomerServiceMetrics();
        GridView1.DataBind();
    }
 
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        DataBind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
 
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of QPR
QPR
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of -Dman100-

ASKER

I figured it out...I just needed to bind the gridview again:

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        DataBind();
    }