Dim name1(100) As String
        Dim Cal1(100) As String


        Dim i As Integer
        For i = 0 To 10 Step 1



            name1(i) = GridView1.SelectedDataKey.Item(1)









        Next i

i want to store the selected value into an array
then display the array in a text box

Label5.Text = name1(0)
        Label6.Text = name1(1)

it woirks however it shows the same array contents for both

eg picke coke for array 1
and pepsi array 2

label5.text will show coke
as will label6.text

i want 5 to eqaul first array
6 to show second array

GridView1.SelectedDataKey.Item(1)

you are always using item '1', you need to change it to use the index (i) to reference the gridview items. Also, is there a reason you are using the SelectedDataKey? If you just want to retrieve each row then use GridView1.Item(columnNo, i) or if its all on one row and you are getting data from each column then GridView1.Item(i, RowNo).

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
error when i replace 1 with i

Hi tried the above no go

the gridview will only ever show one link(we made it that way)
i.e you type coke

the gridview shows details of coke

we click add we save the details to variable

new search run for pepsi

shows details selects that then clicks add

we Prodid(0) should equal coke
prodid(1) should be pepsi

if you only ever have one product in the gridview then you will only get one value from GridView1.SelectedDataKey.Item(1). SelectedDataKey returns the Primary Key value from the selected row as far as i know.
Either way, GridView1.SelectedDataKey.Item(1) is not changing during your loop so each successive entry to name1 has the same value. name1(0)=name1(1)=name1(2) etc.

You need to rethink your code; you say you are storing the details to a variable. Assuming that each time you click 'add' you add them to Prodid() correctly then you need to use THOSE values in your loop:

Dim i As Integer
        For i = 0 To 10 Step 1

            name1(i) = Prodid(i)

        Next i

Also, you realise that For i = 0 to 10 will result in 11 entries, right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.