C# syntax question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have done this before in VB but I am realitively new to C#. I have a
datagrid where the first bound column represents the identity column from the
table. I have designated that first bound column to be hidden. I need to
provide update capibilities to my datagrid and therefore I need to be able to
reference the value in that first column. Could someone please share with me
the correct syntax on how to do that with a hidden column?
 
Mike said:
I have done this before in VB but I am realitively new to C#. (abridged)
Could someone please share with me the correct syntax on how to do
that with a hidden column?
This is more a framework usage question than a language syntax question.
You do this in the exact same way whether you program with Visual
Basic.NET and C#. If you need help to translate Visual Basic.NET to C#
please post the code you want to translate.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Hi, Mike
I think I have a better solution for you. Insted of hidden column for the
ID, you may use the DataKeyField property of the DataGrid. You may set
DataKeyField="ID". Then you can get it whenever you want, all you need to
know is the index of the DataGridItem, which ID you'd like to retrieve.
For example in DataGrid event handler:
int id = Convert.ToInt32(myDataGrid.DataKeys[e.Item.ItemIndex]);

Hope that helps!
Regards,
Kostadin Kostov
 
That solved my problem, thank you very much!

Kostadin Kostov said:
Hi, Mike
I think I have a better solution for you. Insted of hidden column for the
ID, you may use the DataKeyField property of the DataGrid. You may set
DataKeyField="ID". Then you can get it whenever you want, all you need to
know is the index of the DataGridItem, which ID you'd like to retrieve.
For example in DataGrid event handler:
int id = Convert.ToInt32(myDataGrid.DataKeys[e.Item.ItemIndex]);

Hope that helps!
Regards,
Kostadin Kostov

Mike said:
I have done this before in VB but I am realitively new to C#. I have a
datagrid where the first bound column represents the identity column from the
table. I have designated that first bound column to be hidden. I need to
provide update capibilities to my datagrid and therefore I need to be able to
reference the value in that first column. Could someone please share with me
the correct syntax on how to do that with a hidden column?
 
Back
Top