Question

I have a problem using the component GridView of DevExpress on Visual Studio 2010.

What I want to do is really simple. I have a button and when it's clicked, I want to show a message like this: "The column X at row 0 in the gridview has the value Y".

The code of the button is very simple too:

Protected Sub b_test_Click(ByVal sender As Object, ByVal e As EventArgs) Handles b_test.Click
    Dim aux As String
    aux = t_tickets.GetRowValues(0, "numero_de_ticket").ToString

    MsgBox(aux)
End Sub

This code works perfectly, BUT it has a strange behaviour.

If I select the first row in the gridview it works fine. But if I select a diferent row, when the button is clicked I get the following error:

System.Data.MissingPrimaryKeyException: A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure the field name is spelled correctly

I always choose the first row. I dont know why I'm getting this error when I select a different Row.

Can anyone help me?

Was it helpful?

Solution

I think your problem is not the Click function. You are doing a postback that tries to send the selected row to the server side while this row has no keys.

You should check your ASPX file to see the KeyFieldName and check that the datasource identification field is what you have declared.

<dx:ASPxGridView runat="server" Id="t_tickets" KeyFieldName="Id">
...
...
...
</dx:ASPxGridView>

I think that you will find that it is erroneous in your case. This means that what you have specified as KeyFieldName is not a Property member of the datasource object that corresponds to the row of your Grid. (Or it is not part of the select statement in the datasource)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top