【问题标题】:GridView Edit/Update Event NOT firing after 1 click1 单击后不触发 GridView 编辑/更新事件
【发布时间】:2011-07-22 11:29:12
【问题描述】:

我有一个具有普通编辑/更新按钮的 GridView。但是,我的 GV RowUpdating、RowEditing 和 RowCancelingEdit 只需单击 2 次。如果我单击它一次,它不起作用:(

这是我填充所有内容的代码:

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;
    }

这是我在代码后面的全部代码。我在这里做错了什么?

更新:

这是我的 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>

【问题讨论】:

  • 能否请您提供一个页面的标记?

标签: c# asp.net linq linq-to-sql gridview


【解决方案1】:

仅当不是回发时才绑定您的 GV。

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

【讨论】:

    【解决方案2】:

    将 Linkbutton CAUSEVALIDATION 的属性关闭为 false,因为它将停止触发 page_load 事件,除非验证器未通过验证,否则不会触发任何事件,这就是它完成的原因。

    但是在很多情况下,我们必须将 CAUSE VALIDATION 设置为 true 并且还必须更新,但在这种情况下使用 JAVA SCRIPT 是非常不可能的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 2017-09-19
      • 2019-12-16
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多