我有一个 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>
最佳答案
仅在未回发时绑定(bind)您的 GV。
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
//You GV Databinding code
}
}
关于c# - GridView 编辑/更新事件在 1 次单击后未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5425440/