我有一个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>
答案 0 :(得分:4)
仅在不回发时绑定您的GV。
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
//You GV Databinding code
}
}
答案 1 :(得分:1)
将Linkbutton CAUSEVALIDATION的属性设置为false,因为它将停止触发page_load事件为untill&amp;除非验证器未经验证,否则不会触发任何事件,这就是为什么要这样做。
但是在很多情况下我们必须将CAUSE VALIDATION设置为true&amp;也必须更新,但在这种情况下使用JAVA SCRIPT
是非常不可能的