This is a migrated thread and some comments may be shown as answers.

[Solved] Selected item value for parameter

2 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 01 Jul 2008, 11:59 AM
I want to be able to update the value of one field for the selected row of my grid when a button is pressed.

However, I am having trouble trying to get the selected value of the row based on its "DataKeyNames" value.

My stored procedure uses a value of the selected item as a parameter, this is why I want to extract the value.

I've tried things like "selectedvalue" but nothing works dynamically.

My stored procedure is basically "update rows with data where id = @id" and I need that id being the selected grid value.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2008, 12:17 PM
Hi Megan,

Have you gone through the following help article which explains how to access primary key field values for selected items.
Retrieving primary key field values for selected items

Thanks
Princy.

0
Megan
Top achievements
Rank 1
answered on 01 Jul 2008, 01:04 PM

I tried to do this to directly input the value into the value of the parameter:

Dim
iValidationId As New SqlParameter("@iValidationId", SqlDbType.Int, 4)
iValidationId.Value = grdPrices.SelectedItems(0).OwnerTableView.DataKeyValues(grdPrices.SelectedItems(0).ItemIndex)(

"iValidationId")


And it comes up with this error:

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]

Tags
Grid
Asked by
Megan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Megan
Top achievements
Rank 1
Share this question
or