Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,

Please help me to figure out this problem!

I have a Database with 2 tables such as: Person(ID:primarykey, Name) PersonDetail(IDdetail: primarykey, Address, job, house, ID: foreignerkey). These two table has relative as 1-many in Database.

I use gridview control in visual web developer 2008 to display all data from Person table.

And my problem is:

I hope to click on the Gridview row, then display all data from PersonDetail table, which is had a relative with Person table throught ID, to Datagrid or the other Gridview.


How ever i wish to click anywhere on Gridview row, then return the current primary key value. After that, can we used that primary key to select all record, which the same key value in the PersonDetail table, and display on Datagrid or Gridview?

I am a fresh coding. If possible, Please show me an example for my problem!

Thank you so much for your help!
Posted
Updated 25-Oct-11 7:50am
v2

 
Share this answer
 
Comments
VISIONVO 25-Oct-11 13:49pm    
Dear Abhinav,

Thank you for your answer!

How ever i wish to click anywhere on Gridview row, then return the current primary key value. After that, can we used that primary key to select all record, which the same key value in the PersonDetail table, and display on Datagrid or Gridview?

I am a fresh coding. If possible, Please show me an example for my problem!

Thank you so much for your help!
you need to add CellClick Event to your DataGrid. and the code for that will be as follows

C#
private void DataGridView1_CellClick(System.Object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
int id = Convert.ToInt32( DataGridView1.Rows(e.RowIndex).Cells("ID_Column_Name").Value );
	//Now you may use this id anywhere.

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900