ranjenanil
ranjenanil

Reputation: 308

datakeynames in gridview

i have gridview having a

 DataKeyNames="FilterId,ItemId"

field.How can i get each values in both fields in

 gdv_RowEditing 

event.i tried

 protected void gdv_RowEditing(object sender, GridViewEditEventArgs e)
    {
     string a = gdv.DataKeys[e.NewEditIndex].Value[0].ToString(); 
     string b = gdv.DataKeys[e.NewEditIndex].Value[1].ToString();
    }

but it shows error like

'cannot apply indexing with [] to an expression of type object'

Upvotes: 2

Views: 1508

Answers (2)

Manish Parakhiya
Manish Parakhiya

Reputation: 3798

This error cause because you are using

   gdv.DataKeys[e.NewEditIndex].Value[0].ToString();

Here Value is type of object so you can not indexing on object.

to get data key value use Values instead of Value like this

  gdv.DataKeys[e.NewEditIndex].Values[0].ToString();

Hope this helps..

Upvotes: 1

codeandcloud
codeandcloud

Reputation: 55200

Try this

IOrderedDictionary datakeyNames = gdv.DataKeys[0].Values;
string a = datakeyNames["FilterId"].ToString();
string b = datakeyNames["ItemId"].ToString();

Please note that you have to import System.Collections.Specialized

Upvotes: 1

Related Questions