how do i get the value of my primary key in datagrid?

  • Thread starter Thread starter jaYPee
  • Start date Start date
jaYPee said:
i'm wondering how can i get the value of primary key in datagrid.

Do you mean to have it present so that you can click on a row and retrieve
the value, but not see the pk in the grid?

If yes, you can include the column in your data set and set the width of the
column to 0.

Then, in your grids Click event, do something like this.

Dim dc As DataGridCell = MyGrid.CurrentCell 'This will be set to column 0
of the row you selected. You can change that to whatever column you like

Dim intID As Integer = MyGrid.Item(dc)



Hope that helps.
 
Make the first column of you datagrid readonly and invisible:
<asp:BoundColumn Visible="False" DataField="[your uid]" ReadOnly="True"
HeaderText="uid"></asp:BoundColumn>

In your updatecommand refer to it as uid = '" & e.Item.Cells(0).Text & "'

Hope this helps.
Regards!
 
Back
Top