This is a migrated thread and some comments may be shown as answers.

GridLayout....

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dip
Top achievements
Rank 1
Dip asked on 17 Nov 2008, 06:35 PM
Hi Guys,

I have always received a better and efficient ways for doing things in the forum...I have little crazy requirement ...

My DataTable

Country          State           Dev               startDate                EndDate
USA                 FL             A,B,C              5/9/08                     6/8/09
USA                 TX             H,D,C              5/9/08                     6/8/09
USA                 AR             I,J,K                5/9/08                     6/8/09
Canada           ON             A,F,J              11/6/08                   11/08/09
Canada           TO             K,H,J              11/6/08                   11/08/09
Canada           UG             O,F,J              11/6/08                   11/08/09

Now When I have to display in the RadGrid it has to look this...

Country         State               DEV              StartDate            EnadDate
USA                 FL             A,B,C                5/9/08                     6/8/09
                       TX             H,D,C                                 
                       AR             I,J,K
                

Canada           ON             A,F,J              11/6/08                   11/08/09
                       TO             K,H,J                            
                        UG             O,F,J             

IT has too looks something like this....Now the there is another twist ..If a client click then  it has to be highlighted too which I have show it by Bold  fonts in USA....
Please don't suggest me the Hierachy Level in Grid..Beacuse I already suggested it, and it was denied...Any other help will be appriciated ...

thanks,
DIP

2 Answers, 1 is accepted

Sort by
0
d
Top achievements
Rank 1
answered on 17 Nov 2008, 09:31 PM

It sounds like you already have a solution for this but are looking for a better one? If so it would be best to post your solution.

I had a similar requirement to yours.

I assume for your problem the stored procedure is returning the data Ordered By country.

What I did was... add "<br />" to the end of each line for State, Dev, startDate and endDate to produce a line break. Then output the line once and with the "<br /> it will look how you want it.

For example:

When country = USA.

The first time we encounter USA we don't want to add it to the grid, we just need to keep track of the non-country values (can use temp string variables, each time a value is added we need to insert a <br /> after it). When we hit the 3rd row for USA we want to output the row along with all the values from the previous rows.

Now to code it we need to keep track of the current country, when the NEXT country is different or we are on the last row we want to output the country and the state,dev, startDate and endDate we've been keeping track of for the country (the process outlined above).

USING tempState, tempDev, tempStart, tempEnd variables
FIRST RUN:
tempState = "FL", tempDev="A,B,C", tempStart="5/9/08", tempEnd="6/8/09"
SECOND RUN:
tempState = "FL<br/>TX", ... and so on
THIRD RUN:
tempState = "FL<br/>TX<br/>AR", ... and so on
On this run we need to see that the next country is not USA so we output the line with the country and tempState, tempDev, tempStart, tempEnd.

Maybe there is a better radgrid way to do what you want but being fairly new to radgrid and having a deeper grasp on programming and c#; the way I did it was quick and easy for me.

 

 

 

 

0
Dip
Top achievements
Rank 1
answered on 18 Nov 2008, 01:04 AM
I think I have something similar what you did...

private string Country,state,dev;

//Created a Tmp Table
DataTable Func = new DataTable();
Func.Columns.Add(
"Country", typeof(string));
Func.Columns.Add(
"State", typeof(string));
Func.Columns.Add(
"Dev", typeof(string));

DataRow dr;
foreach (DataRow row in tmp.Rows)
{
if (row[0] == Country )
{
continue;
}
else
{
dr = Func.NewRow();
dr[
"Country"] = row[0];

IEnumerable<DataRow> query =from tmp1 in tmp.AsEnumerable()  where tmp1.Field<string>("Country") == row[0]   select tmp1;
foreach (DataRow ha in query)
{
state += ha[1] +
"<br/>"; //Adding all state with <Br />
dev += ha[2] +
"<br/>"; ///Adding all dev with <Br />
}
dr[
"State"] = state;
dr[
"Dev"] =dev;
Country = row[0].ToString();
state =
"";
dev =
"";
 
Func.Rows.Add(dr);
}

Tags
Grid
Asked by
Dip
Top achievements
Rank 1
Answers by
d
Top achievements
Rank 1
Dip
Top achievements
Rank 1
Share this question
or