Search code examples
c#asp.netweb-controls

How to use DataKeys and DataItemIndex


I need some advice how to use DataKeys and DataItemIndex fro a GRIDVIEW.

I need take the values for an item "ROW" in a "GRIDVIEW" and associate it to "MembershipUser".

I get an error "Make sure all arguments to this method have valid values as defined by the invoked method."

Any ideas??? Thanks for your help BYE!

 protected void uxRoleCheckBoxSelector_CheckChanged(object sender, EventArgs e)
        {
            CheckBox activeCheckBox = (CheckBox)sender;
            GridViewRow row = (GridViewRow)activeCheckBox.NamingContainer;
            string myUserName = (string)uxUserListDisplayer.DataKeys[row.DataItemIndex].Value;
            MembershipUser myUser = Membership.GetUser(myUserName);

        }

Solution

  • How many keys you have in datakeynames? if you have more than 1 key try:

    uxUserListDisplayer.DataKeys[row.DataItemIndex]["Kayname"]
    

    where keyname is the name of the key you wanth read.