BaseDataList.DataKeys

D

Dave

Can anybody help me with BaseDataList.DataKeys?
I always get this error: Exception Details:
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection. Parameter name:
index.
May be there is some demo about how to use it?
 
K

Karl

Maybe it would help if you showed us how you were currently using it.

Basically the datakeys are stored in a DataKey collection, and you typically
access the key for the row being edited via:

dim key as integer = cint(YourLIstID.DataKeys(e.Item.ItemIndex))

Karl
 
G

Guest

You might want to try this first -- the sample code on MSDN is wrong in that
it leaves out a key bit: You have to explicitly assign a key field prior to
binding to the datagrid, even though the dataset may appear to have already
assigned it for you.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SQLDataAdapter1.Fill(DataSet1)
If Not IsPostBack Then
DataGrid1.DataKeyField() = "MyPrimaryKeyFieldName"
DataGrid1.DataBind()
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top