gpt4 book ai didi

c# - Gridview 不更新值

转载 作者:太空宇宙 更新时间:2023-11-03 19:17:30 24 4
gpt4 key购买 nike

我试图让我的 gridview 更新 SQL 记录,但它没有更新值。

这是 aspx 代码:

<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="false" 
onrowcancelingedit="GridView1_RowCancelling"
OnRowDeleting ="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
DataKeyNames="RID"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt">


<Columns>

<asp:TemplateField Visible="false" HeaderText="RID">
<ItemTemplate>
<asp:Label runat="server" ID="RID" Text='<%#Bind("RID")%>' />
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Short Description">
<ItemTemplate>
<asp:Label runat="server" ID="short_lbl" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="SHORT_DESCRIPTION" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valShort" ControlToValidate="SHORT_DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label runat="server" ID="desc_label" Text='<%#Bind("DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="DESCRIPTION" Text='<%#Bind("DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valLast" ControlToValidate="DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>



<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
<br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

以及更新函数本身。

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string s = GridView1.DataKeys[e.RowIndex].Value.ToString();
Label RID = GridView1.Rows[e.RowIndex].FindControl("RID") as Label;
TextBox SHORT_DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("SHORT_DESCRIPTION") as TextBox;
TextBox DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("DESCRIPTION") as TextBox;

String UpdateQuery = string.Format("UPDATE TAXONOMIES SET SHORT_DESCRIPTION='{0}', DESCRIPTION='{1}' WHERE RID = {2}", SHORT_DESCRIPTION.Text, DESCRIPTION.Text, Convert.ToInt32(RID.Text));

GridView1.EditIndex = -1;
BindGridData(UpdateQuery);

}

如果我设置一个断点并查看该值,我可以看到这不是新输入的值。我不确定发生了什么。

最佳答案

我认为问题在于您在 page-load 事件上绑定(bind)了 grid
尝试在 if (!IsPostBack)

中绑定(bind)它

例子

private void Page_Load()
{
if (!IsPostBack)
{
//bind your grid here.
}
}

关于c# - Gridview 不更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15104161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com