Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView and retrieving data 1

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I have a grid view consisting of options for a computer ([x] = a tick box)

Code Description Price
2323 Mouse £4.00 [x]
4555 Keyboard £8.00 [x]
9898 Memory £10.49 [x]
54647 Cable £10.00 [x]
where the user can tick the items they want then click on the 'add to cart' button.

Setting DataKeyNames="txtProductCode" in the GridView enables me to retrieve the code of the item ticked using

Dim sOptionCode As String
Dim cb As CheckBox

For Each row As GridViewRow In gvOptionsList.Rows
cb = DirectCast(row.FindControl("chkBox"), CheckBox)
If cb IsNot Nothing AndAlso cb.Checked Then
sOptionCode = gvOptionsList.DataKeys(row.RowIndex).Value
lblTest.Text += sOptionCode + ","
End If
Next

and I can retrieve the information from the tickbox using FindControl. I can't figure how I obtain the Description and Price from the gridview though (these are just bound fields)

<asp:BoundField DataField="txtDescription" HeaderText="Description" SortExpression="txtDescription" />

Can anyone advise? is it possible?

Thanks
Andy
 
Just use row.cells(x).text
Where x is the cell index of the data you want.
 
Thanks jbenson001 that works great
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top