DataKeyField="设置为你的主键列"
就可以通过这个属性等到值

解决方案 »

  1.   

    DataGrid的DataKeyField属性?有这个属性吗?
      

  2.   

    <ASP:DataGrid id="MyDataGrid" runat="server"
          Width="800"
          BackColor="#ccccff"
          BorderColor="black"
          ShowFooter="false"
          CellPadding=3
          CellSpacing="0"
          Font-Name="Verdana"
          Font-Size="8pt"
          HeaderStyle-BackColor="#aaaadd"
          OnEditCommand="MyDataGrid_Edit"
          OnCancelCommand="MyDataGrid_Cancel"
          OnUpdateCommand="MyDataGrid_Update"
          DataKeyField="au_id"
          AutoGenerateColumns="false"
        >
      

  3.   

    <Columns>
            <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" 
                UpdateText="Update"  ItemStyle-Wrap="false"/>
            <asp:BoundColumn HeaderText="au_id" SortExpression="au_id" 
                ReadOnly="True" DataField="au_id" ItemStyle-Wrap="false"/>
            <asp:TemplateColumn HeaderText="au_lname" SortExpression="au_lname">
              <ItemTemplate>
                <asp:Label runat="server" 
                    Text='<%# DataBinder.Eval(Container.DataItem, "au_lname") %>'/>
              </ItemTemplate>
              <EditItemTemplate>
                <asp:TextBox runat="server" id="edit_LName" 
                    Text='<%# DataBinder.Eval(Container.DataItem, "au_lname") %>'/>
              </EditItemTemplate>
            </asp:TemplateColumn>
    ...............................
    你可以随便写了,主键在上面已经定了后台代码举例:   public void MyDataGrid_Delete(Object sender, 
          DataGridCommandEventArgs E) 
       {
          String deleteCmd = "DELETE FROM Authors WHERE au_id = @Id";
          SqlCommand myCommand = new SqlCommand(deleteCmd, myConnection);
          myCommand.Parameters.Add(new SqlParameter("@Id", 
             SqlDbType.VarChar, 11));
          // Initialize the SqlCommand "@Id" parameter to the ID of the row
          // that was clicked.
          myCommand.Parameters["@Id"].Value = 
             MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
          // Connect to the database and delete the specified row.
          myCommand.Connection.Open();
          // Test whether the delete was accomplished, and display the 
          // appropriate message to the user.
          try 
          {
             myCommand.ExecuteNonQuery();
             Message.InnerHtml = "<b>Record Deleted</b><br>";
          }
          catch (SqlException) 
          {
             Message.InnerHtml = "ERROR: Could not delete record";
             Message.Style["color"] = "red";
          }
          // Close the connection.
          myCommand.Connection.Close();
          // Rebind the DataGrid to show the updated information.
          BindGrid();
       }==================================
          myCommand.Parameters["@Id"].Value = 
             MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
    这句是关键代码。
      

  4.   

    谢谢,不过oracle 怎么写删除?