按钮不提交第一次点击,但在随后的点击提交previous信息 [英] Button does not submit on first click, but on subsequent click submits previous information
本文介绍了按钮不提交第一次点击,但在随后的点击提交previous信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提出一个可编辑的 GridView控件
,但我的问题是,每当我点击一个按钮,没有任何反应。当我点击我第二次看到previous点击时发生了什么。
I am making an editable GridView
, but my problem is that whenever I click on a button nothing happens. When I click a second time I see what happened during the previous click.
<%@ Page Title="Home Page" Language="C#"
MasterPageFile="~/Site.master" AutoEventWireup="true"
EnableEventValidation="true"
CodeBehind="Default.aspx.cs" Inherits="BeheerSysteemWeb._Default" %>
<asp:Content ID="HeaderContent" runat="server"
ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content
ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
<asp:GridView ID="GridView1" runat="server"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating" AutoGenerateColumns="False">
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" />
<asp:TemplateField HeaderText="36">
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtSpoor" Text="TramNummer" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</h2>
</asp:Content>
codebehind
namespace BeheerSysteemWeb
{
public partial class _Default : System.Web.UI.Page
{
List<string> leeg = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
leeg.Add("");
leeg.Add("");
leeg.Add("");
leeg.Add("");
GridView1.DataSource = leeg;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
GridView1.EditIndex = -1;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txtSpoor = (TextBox)row.FindControl("txtSpoor");
e.Cancel = true;
GridView1.EditIndex = -1;
}
}
}
我怎样才能按钮,在ASP.NET工作?
How can I get the button to work in ASP.NET ?
推荐答案
我不知道这是否是这里的问题,但你需要的行动是后添加在每个页面调用数据,并作出的DataBind:
I am not sure if this is the issue here, but you need to add your data on every page call, and make DataBind after the actions as:
public partial class _Default : System.Web.UI.Page
{
List<string> leeg = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
LoadData();
if (!Page.IsPostBack)
{
GridView1.DataBind();
}
}
private void LoadData()
{
leeg.Add("");
leeg.Add("");
leeg.Add("");
leeg.Add("");
GridView1.DataSource = leeg;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txtSpoor = (TextBox)row.FindControl("txtSpoor");
e.Cancel = true;
GridView1.EditIndex = -1;
GridView1.DataBind();
}
}
试一下,看是否解决您的问题。
Try that to see if you solve your issue.
这篇关于按钮不提交第一次点击,但在随后的点击提交previous信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文