Click here to Skip to main content
15,436,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

the sql code i used is as follows
SQL
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

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
Posted
Updated 22-Apr-12 22:18pm
v2

 
Share this answer
 
Comments
Ragi Gopi 23-Apr-12 5:16am     CRLF
Sorry this is not the answaer.. i am talking about, if it happens with more than 6 or seven coloumns.
Arav Pradeep Gupta 23-Apr-12 5:20am     CRLF
Gopi, Did you try the Solution 1.? One thing if you have couple of colomns then you need to apply the same condition.
Sandeep Mewara 23-Apr-12 5:52am    
Not sure what do you mean by 'happens with more..'. Articles above are for removing duplicates as you asked for.
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
 
Share this answer
 
v3

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