在C#中不更新Gridview中的ID列 [英] Not updating Id column in Gridview in c#

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

问题描述

Hai朋友,


我正在使用gridview进行更新和删除操作.在更新操作中,它正在更新bugsummary,bugdescription列,但不更新BugId列.请帮助我.以下是此代码.在这里,我没有将BugId用作主键.

Hai friends,


I am using gridview for update and delete operations.In the update operation it is updating bugsummary,bugdescription columns but not updating BugId column.Plz help me.Below is the code for this.Here I am not using BugId as primary key.

<asp:GridView ID="grdEmployee" runat="server" AutoGenerateEditButton="true" DataKeyNames="BugId"
            AutoGenerateDeleteButton="true" onrowediting="grdEmployee_RowEditing" AutoGenerateColumns="false"
            onrowupdating="grdEmployee_RowUpdating" ShowFooter="true"
            onrowcancelingedit="grdEmployee_RowCancelingEdit" 
         onrowdeleting="grdEmployee_RowDeleting" 
         >

           <Columns>
            <asp:TemplateField HeaderText="BugId">
    <ItemTemplate>
    <%#Eval("BugId")%>
    </ItemTemplate> 
    <EditItemTemplate>
    <asp:TextBox ID="tt1"
         Text=''<%#Eval("BugId") %>''
         runat="server"></asp:TextBox>
    </EditItemTemplate> 
    <FooterTemplate>
    <asp:TextBox ID="txtno" runat="server">
                    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="BugDescription">
    <ItemTemplate>
    <%#Eval("BugDescription")%>
    </ItemTemplate>  
    <EditItemTemplate>
    <asp:TextBox ID="tt2"
         Text=''<%#Eval("BugDescription")%>''
         runat="server"></asp:TextBox>
    </EditItemTemplate>   
    <FooterTemplate>
    <asp:TextBox ID="txtname" runat="server">
                    </asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="BugSummary">
    <ItemTemplate>
    <%#Eval("BugSummary")%>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="tt3"
             Text=''<%#Eval("BugSummary") %>''
             runat="server"></asp:TextBox>
    </EditItemTemplate>
     <FooterTemplate>
    <asp:TextBox ID="txtsal" runat="server">
                    </asp:TextBox>
    </FooterTemplate>   
    </asp:TemplateField>
   
   <asp:TemplateField>   
    <FooterTemplate>   
  
    </FooterTemplate>
    </asp:TemplateField>
          
           </Columns>
        </asp:GridView>


protected void grdEmployee_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       int Eno = Int32.Parse(grdEmployee.DataKeys[e.RowIndex].Value.ToString());
       TextBox Name = (TextBox)(grdEmployee.Rows[e.RowIndex].FindControl("tt2"));
       TextBox Salary = (TextBox)(grdEmployee.Rows[e.RowIndex].FindControl("tt3"));

       string Ename = Name.Text;
       string Esalary = Salary.Text;
       int result = obj.update(Eno, Ename, Esalary);

       grdEmployee.EditIndex = -1;
       bind();
   }





Thanks in Advance.

推荐答案

在GridView的DataKeyNames = "BugId"属性中,我想它是主键.
您正在将BugId作为Eno发送到方法obj.updat e.
因此,请仔细查看它以及它执行的SQL查询.

我假设它会使用Ename和Esalary更新具有BugId的行.
From the DataKeyNames = "BugId" property of GridView, I guess it is the Primary key.

You are sending the BugId as Eno to method obj.update.
So, look at it closely and the SQL Query which it executes.

I assume that it updates the row which has this BugId with the Ename and Esalary.


希望如此,因此您不会在查询中更新Eno
你只是在做

更新.....用
设置Ename,ESalary 伊诺的行为

您可能不更新Eno的地方
如果要更新primay键,请转到以下链接
social.msdn.microsoft.com/forums/update-primary-key-column-in-sql-server
Hope so you are not updating Eno in your query
You are just doing

Update ..... set Ename,ESalary with
the condion of Eno

Where you may not updating Eno
If you want to update primay key the go to following link
social.msdn.microsoft.com/forums/update-primary-key-column-in-sql-server


这篇关于在C#中不更新Gridview中的ID列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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