GridView 编辑/更新事件在 1 次单击后未触发
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当 GV 不是回发时才绑定它。
Bind your GV only if it isn't postback.
将 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