GridView控件不更新值 [英] Gridview not updating value

查看:353
本文介绍了GridView控件不更新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to make my gridview update a SQL record but it is not updating the values.

下面是ASPX code:

Here is the aspx code:

<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);

}

如果我把一个断点,并期待在价值,我可以看到,是不是在价值新类型。我不知道是怎么回事。

If I put a breakpoint and look at the value, I can see that is is not the newly typed in value. I'm not sure what is going on.

推荐答案

我认为这个问题是你要绑定您电网页面级负载事件。

尝试绑定,如果(!的IsPostBack)

I think the problem is you are binding you grid on the page-load event.
try binding it in if (!IsPostBack)

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

这篇关于GridView控件不更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆