Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select RoomNo,Minor_Code from room where active = 'A' and Dateofcrs = '1/7/2013' and Sess = 'PM';

Output as follows for the above query


Room Course

11 EFA
22 PST
23 PH2
31 AFF
32 PSCRB
34 TFC

My gridview as follows


Room Course Room Course Room Course

11 21 31

12 22 32

13 23 33

14 24 34


in the gridview, for the course that to be retrieved from the database and display in to the gridview according to Room.


I want output as follows in the gridview(course name is retrieved from the database)


Room Course Room Course Room Course

11 EFA 21 31 AFF

12 22 PST 32 PSCRB

13 23 PH2 33

14 24 34 TFC


for that how can i do using csharp.



Rgds,
Narasiman P.
Posted
Comments
jaideepsinh 5-Jul-13 7:08am    
You want this type of output from you table or from where you get this type of output.

Basically you have a table that represent class rooms and you want to show which courses are being given on each room... correct?

The easiest thing is to create a DataTable that will be the datasource of your grid and fill it properly matching the existing rooms and the result of the query.
Create 2 loops of 4 and build your table validation if each room number is on the query result, if so, add the course name.
 
Share this answer
 
Concider DT as ur grids DataSourse,

Add your select querie's result to a collection...

C#
DataTable DT = new DataTable();

            Dictionary<int, string> dic = new Dictionary<int, string>();
            string course = "";
            foreach (DataRow r in DT.Rows)
            {
                if (dic.TryGetValue(r[0], out course))
                {
                    r[1] = course;
                }
                if (dic.TryGetValue(r[2], out course))
                {
                    r[3] = course;
                }
                if (dic.TryGetValue(r[4], out course))
                {
                    r[5] = course;
                }
            }


Hope it works..
 
Share this answer
 
v2

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