我已经使用了下面的代码GridViewRowUpdating
,但是单击更新按钮后,它采用旧值。我通过断点检查GridViewRowIpdating
,所有文本框都有旧值。并且新输入的值不会抓取。
我在谷歌尝试了很多,但我无法解决问题。
protected void GridViewDocuments_Search_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
_DataContext = new EDMSDataContext();
int _Docid = (int)GridViewDocuments_Search.DataKeys[e.RowIndex].Value;
TextBox DocumentNo = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("DocumentNo");
TextBox title = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("title");
TextBox unit = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("unit");
TextBox originator = (TextBox)GridViewDocuments_Search.Rows[e.RowIndex].FindControl("originator");
_DataContext.updateDoc(_Docid, DocumentNo.Text, title.Text, unit.Text, originator.Text);
_DataContext.SubmitChanges();
GridViewDocuments_Search.EditIndex = -1;
var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
}
protected void GridViewDocuments_Search_RowEditing(object sender, GridViewEditEventArgs e)
{
//var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
// GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.EditIndex = e.NewEditIndex;
GridViewDocuments_Search.DataBind();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
_DataContext = new EDMSDataContext();
var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
GridViewDocuments.Visible = false;
GridViewDocuments_Search.Visible = true;
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
}
网格视图标记:
<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False
Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand" OnRowDeleting="GridViewDocuments_Search_RowDeleting"
DataKeyNames="DocID" PageSize="100"
onrowcancelingedit="GridViewDocuments_Search_RowCancelingEdit"
onrowediting="GridViewDocuments_Search_RowEditing"
onrowupdating="GridViewDocuments_Search_RowUpdating" >
<Columns>
<asp:TemplateField HeaderText = "Details">
<ItemTemplate>
<asp:Button ID ="btn_Show" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%#
Container.DataItemIndex%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DocNo">
<EditItemTemplate>
<asp:TextBox ID="DocumentNo" runat="server" Text='<%# Eval("DocumentNo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DocumentNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="title">
<EditItemTemplate>
<asp:TextBox ID="title" runat="server" Text='<%# Eval("title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DocID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("DocID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("DocID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Originator">
<EditItemTemplate>
<asp:TextBox ID="Originator" runat="server" Text='<%# Eval("Originator") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Originator") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit">
<EditItemTemplate>
<asp:TextBox ID="Unit" runat="server" Text='<%# Eval("Unit") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Unit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
GridViewDocuments_Search_RowCommand
protected void GridViewDocuments_Search_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
_DataContext = new EDMSDataContext();
int _Docid = (int)GridViewDocuments_Search.DataKeys[rowindex].Value;
switch (e.CommandName)
{
case "Details":
Response.Redirect("~/Documentfortest.aspx?DocID=" + _Docid);
break;
case "Delete":
_DataContext.DeleteDoc(_Docid);
_DataContext.SubmitChanges();
break;
}
var query = _DataContext.spQuickSearchDoc(txtSearchKeywords.Text);
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
//UpdatePanel1.Update();
}