RG-3
RG-3

Reputation: 6188

GridView Edit/Update Event NOT firing after 1 click

I have a GridView which has normal Edit/Update button. However, my GV RowUpdating, RowEditing & RowCancelingEdit is working with 2 clicks. If I am clicking it once, its not working :(

Here is the code where I am populating everything:

public partial class Testing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         string getEntity = Request.QueryString["EntityID"];
         int getIntEntity = Int16.Parse(getEntity);
         using (OISLinq2SqlVs1DataContext dt = new OISLinq2SqlVs1DataContext())
         {
             var tr = from r in dt.Users
                      join s in dt.Entities on r.Entity_ID equals s.ID
                      where s.ID == getIntEntity
                      select new
                      {
                          s.Name,
                          r.FirstName,
                          r.LastName,
                          s.Email,
                          //r.Email,
                          r.UserID,
                          r.Pwd,
                          s.Company,
                          s.Description,
                          s.Phone,
                          s.Fax,
                          s.WebSite
                          
                      };

             gvShowRegistration.DataSource = tr;
             gvShowRegistration.DataBind();
         }
    }

    protected void gvShowRegistration_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        OISLinq2SqlVs1DataContext dt = new OISLinq2SqlVs1DataContext();
    }

    protected void gvShowRegistration_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvShowRegistration.EditIndex = e.NewEditIndex;
    }

    protected void gvShowRegistration_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvShowRegistration.EditIndex = -1;
    }

This is my whole code at code behind. What I am doing wrong here?

Update:

Here is my GridView:

<asp:GridView ID="gvShowRegistration" runat="server" 
     Height="204px" Width="678px" 
    OnRowEditing = "gvShowRegistration_RowEditing" 
    OnRowUpdating = "gvShowRegistration_RowUpdating" 
    OnRowCancelingEdit = "gvShowRegistration_RowCancelingEdit" CssClass="menu">
    <Columns>
    <asp:CommandField HeaderText="Edit" ShowEditButton="True" ShowHeader="True" ShowSelectButton="True" />
    
    </Columns>
 </asp:GridView>

Upvotes: 2

Views: 4509

Answers (2)

gbs
gbs

Reputation: 7266

Bind your GV only if it isn't postback.

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack){
        //You GV Databinding code
    }
}

Upvotes: 4

Lokesh
Lokesh

Reputation: 11

Turn off the property of Linkbutton CAUSEVALIDATION to false as it will stop firing page_load event as untill & unless validators are not validated no event will be fired thats why it is done.

But there are many cases when we have to set CAUSE VALIDATION true & also have to update but it is quite implossible in such case use JAVA SCRIPT

Upvotes: 1

Related Questions