从Gridview中选择一行并将数据绑定到Datagrid/Gridview [英] Select a row from Gridview and binding data to Datagrid / Gridview

查看:67
本文介绍了从Gridview中选择一行并将数据绑定到Datagrid/Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

请帮我解决这个问题!

我有一个包含2个表的数据库,例如:Person(ID:primarykey,Name)PersonDetail(IDdetail:primarykey,Address,job,house,ID:foreignerkey).这两个表在数据库中相对为1.

我在Visual Web Developer 2008中使用gridview控件来显示Person表中的所有数据.

我的问题是:

我希望单击Gridview行,然后显示从PersonDetail表到Datagrid或另一个Gridview的所有数据,该数据与Person表的ID相对.

我希望如何在Gridview行上单击任意位置,然后返回当前的主键值.之后,我们可以使用该主键来选择所有记录,在PersonDetail表中该键值相同,并显示在Datagrid或Gridview上吗?

我是一个新鲜的编码.如果可能的话,请给我举个例子说明我的问题!

非常感谢您的帮助!

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!

推荐答案

代码项目-常见问题系列1:ASP.Net GridView [ ^ ]可能会有所帮助.
Code Project - Frequently Asked Questions Series 1: The ASP.Net GridView[^] might help.


您需要将CellClick事件添加到DataGrid中.的代码如下

you need to add CellClick Event to your DataGrid. and the code for that will be as follows

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.

}


这篇关于从Gridview中选择一行并将数据绑定到Datagrid/Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆