Concept of datakeyname in grid view?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnagJohari
    New Member
    • May 2010
    • 96

    Concept of datakeyname in grid view?

    i wanna know the concept of datakey name in grid view how its work...
    when we connect it to the sqldatasource when i updata the field
    i write the following code:

    <asp:SqlDataSou rce ID="datasource1 " ProviderName="S ystem.Data.SqlC lient" runat="server" ConnectionStrin g="<%$Connectio nStrings:Connec tionString%>" SelectCommand=" Select * From ManageClient"
    UpdateCommand=" Update ManageClient Set ClientName=@Cli entName,Address =@Address,Mobil eNo=@MobileNo,I mage=@Image Where ClientId=@Clien tId"></asp:SqlDataSour ce>


    in the above code we donot use <updateparamete r> tag can u explain why
    when i connect it to the grid view & i keep the datakeynames="C lientId"
    Thank you
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    "When the DataKeyNames property is set, the GridView control automatically creates a DataKey object for each row in the control. The DataKey object contains the values of the field or fields specified in the DataKeyNames property. The DataKey objects are then added to the control's DataKeys collection. Use the DataKeys property to retrieve the DataKey object for a specific data row in the GridView control."
    MSDN


    "Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source. You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work. The values of these key fields are passed to the data source control in order to specify the row to update or delete.

    When the DataKeyNames property is set, the GridView control automatically populates its DataKeys collection with the values from the specified field or fields, which provides a convenient way to access the primary keys of each row."

    Basically it tells your Gridview about the primary key.

    Comment

    • AnagJohari
      New Member
      • May 2010
      • 96

      #3
      Originally posted by PRR
      "When the DataKeyNames property is set, the GridView control automatically creates a DataKey object for each row in the control. The DataKey object contains the values of the field or fields specified in the DataKeyNames property. The DataKey objects are then added to the control's DataKeys collection. Use the DataKeys property to retrieve the DataKey object for a specific data row in the GridView control."
      MSDN


      "Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source. You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work. The values of these key fields are passed to the data source control in order to specify the row to update or delete.

      When the DataKeyNames property is set, the GridView control automatically populates its DataKeys collection with the values from the specified field or fields, which provides a convenient way to access the primary keys of each row."

      Basically it tells your Gridview about the primary key.
      tnx i have a one more Question.
      i create a function of update as well as delete now i want to call these methods so that i can do updation in grid view by using sql data source
      , i donot want to write query on aspx page. just wanna acess from code behind can i do this........?

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by AnagJohari
        tnx i have a one more Question.
        i create a function of update as well as delete now i want to call these methods so that i can do updation in grid view by using sql data source
        , i donot want to write query on aspx page. just wanna acess from code behind can i do this........?
        Please start a separate thread for new questions. That way it will be helpful for others too :) Take care

        Comment

        Working...