Click here to Skip to main content
15,881,744 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



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

<pre>
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 </pre>



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

XML
<pre>D_id   Designation name    Employees
1   Consultant              GHI
2   Project Lead            DEF
                            PQR
3   Programmer              ABC
                            JKL
                            MNO</pre>






please help me thanks in advance
Posted
Updated 22-Apr-12 20:34pm
v2
Comments
Mike Hankey 23-Apr-12 2:26am    
You need to show the SQL statement you're using.
Ragi Gopi 23-Apr-12 2:35am    
SQL i used is Updated in my question.
thanks in advance
Ragi Gopi 23-Apr-12 3:09am    
Had updated my question

1 solution

Hey,

If you get data from sql---

<pre lang="SQL">

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



Then you should work on RowDataBound event of the grid to taking a string Variable to put the initial Designation name value.

string sDesignation=string.Empty;
initialize with the Designation name value.
then check with

if(sDesignation!=current Designation name value)
{
// code to set the Designation name
}

sDesignation retail the Designation name value.


TRY................ With this logic.
 
Share this answer
 
Comments
Ragi Gopi 23-Apr-12 2:36am    
Can you make it clear.
Ragi Gopi 23-Apr-12 2:37am    
ok will try thanks..
Arav Pradeep Gupta 23-Apr-12 2:43am    
Look at this now Mey Be Help........
protected void Grid_RowDataBound(Object sender, GridViewRowEventArgs e)
{

if(e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
Label lbl= ((Label)e.Row.FindControl("Designation "));
sDesignation = "" + e.Row.Cells["ColomnName"].Text + "";
if(sDesignation!=e.Row.Cells["ColomnName"].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.

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