我想用来自两个以上SQL Server表的数据填充网格视图 [英] i want to populate grid view with data from more than two sql server tables

查看:88
本文介绍了我想用来自两个以上SQL Server表的数据填充网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai all
我想用来自sql server表的数据填充网格视图.

表格如下:

第一张表:个人资料:

hai all
i want to populate grid view with data from sql server tables.

the tables are as follows:

first table: Profile:

Id	Name 	Age Designation_code
1	ABC	22	3
2	DEF	24	2
3	GHI	25	1
4	JKL	23	3
5	MNO	22	3
6	PQR	25	2


第二张表:名称:


Second Table: Designation:

D_id	Designation_name Designation_code
1	Consultant	E1
2	Project Lead	E2
3	Programmer	E3


网格视图中的结果应采用这种方式


the result in the grid view should be this way

D_id	Designation_name	Employees
1	Consultant	            GHI
2	Project Lead                DEF
                                    PQR
3	Programmer	            ABC
                                    JKL
                                    MNO


我使用的sql代码如下


the sql code i used is as follows

SELECT p.Id,d.Designation_name,p.Name as Employee
FROM profile p
LEFT OUTER JOIN Designation d
ON p.Designation_code=d.Designation_code


我知道结果的sql,但结果显示如下:


I know the sql for the result but.. the result is displayed like this

D_id    Designation name    Employees
1   Consultant              GHI
2   Project Lead            DEF
3   Project Lead            PQR
4   Programmer              ABC
5   Programmer              JKL
6   Programmer              MNO 


我想要我显示的结果.我应该怎么做才能以这种方式在网格视图中获取两个表的数据


i want the result as i showed. what should i do to get the data of two tables in the grid view this way

D_id   Designation name    Employees
1   Consultant              GHI
2   Project Lead            DEF
                            PQR
3   Programmer              ABC
                            JKL
                            MNO


请事先帮助我


please help me thanks in advance

推荐答案

在这里,您去:
从网格视图中消除重复值 [ ^ ]
如何在Gridview控件中隐藏重复的行值 [
Here you go:
Eliminate Duplicate Values from the Grid View[^]
How do I Hide duplicate row values in a Gridview Control [^]


protected void Grid_RowDataBound(Object sender, GridViewRowEventArgs e)
 {
 if(e.Row.RowType == DataControlRowType.DataRow)
 {
 Label lbl= (Label)e.Row.FindControl("ID Of Control taken for Designation  into the inline page"));

if(sDesignation!=e.Row.Cells[Index].Text) 
{ lbl.Text=sDesignation;}
 
 sDesignation=e.Row.Cells["ColomnName"].Text;
 } 
}
 NOTE- sDesignation this variable out of this event. No need create the instanse each time calling.As a Global


这篇关于我想用来自两个以上SQL Server表的数据填充网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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