GridView 编辑/更新事件在 1 次单击后未触发

发布于 2024-10-27 01:27:00 字数 2340 浏览 0 评论 0原文

我有一个 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-11-03 01:27:00

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

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

Bind your GV only if it isn't postback.

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack){
        //You GV Databinding code
    }
}
荒人说梦 2024-11-03 01:27:00

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文