Hi, I need some help, how can i create a dynamic grid using a list and databind? what i have so far is the following: I have a grid that display day and time and shows two different colors if the cell value is a different value display blue else red. that's done.
what I need is if the list reads that there are two rooms on the header "Room" to genearte a second grid with the data similar as the first one that is already there.
Here is my aspx code:
<
DisplayLayout Version="4.00" SelectTypeRowDefault="Extended" Name="GridSummary" AllowSortingDefault="OnClient" AllowColSizingDefault="Free" RowHeightDefault="20px" TableLayout="Fixed" RowSelectorsDefault="No" AllowColumnMovingDefault="OnServer" HeaderClickActionDefault="SortMulti" StationaryMargins="Header" BorderCollapseDefault="Separate" StationaryMarginsOutlookGroupBy="True">
ClientSideEvents MouseOverHandler="Over" MouseOutHandler="Out" />
FrameStyle BackColor="Window" BorderColor="Transparent" BorderWidth="1px"
Pager MinimumPagesForDisplay="2">
PagerStyle BackColor="LightGray" BorderWidth="1px" BorderStyle="Solid">
BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px"></BorderDetails>
</
PagerStyle>
Pager>
EditCellStyleDefault BorderWidth="0px" BorderStyle="None"></EditCellStyleDefault>
FooterStyleDefault BackColor="LightGray" BorderWidth="1px" BorderStyle="Solid">
FooterStyleDefault>
HeaderStyleDefault HorizontalAlign="Left" BackColor="LightGray" BorderStyle="Solid">
HeaderStyleDefault>
RowStyleDefault BackColor="Window" BorderColor="Silver" BorderWidth="1px" BorderStyle="Solid" Font-Names="Microsoft Sans Serif" Font-Size="11pt">
<Padding Left="3px"></Padding>
BorderDetails ColorLeft="Window" ColorTop="Window"></BorderDetails>
RowStyleDefault
>
="True">
="Solid">
="200px">
="11px">
Over(tableName, itemName, type)
{
(type == 0)
// Are we over a cell
row = igtbl_getRowById(itemName);
row.setSelected(
);
}
Out(tableName, itemName, type)
// Get the grid
// Get the current active row
)
// We verify if there is a selection made by click, if there is, we let it selected
(rowActive.Id != row.Id)
else
Now, here is my .cs code:
protected
e)
_level = 2;
token =
.SendPlainText);
//Apply Security Token to web service
wse.SetClientCredential(token);
//Set Client policy to web service
wse.SetPolicy(
//Set Security Token
>(wse3.getACADDE(SessionVal, SessionCampus, SessionBuilding, SessionRoom, _level));
//this.DashboardGridContainer1.Columns
list)
startHour, endHour;
startMinute, endMinute;
startTime, endTime;
try
// extract hours and minutes
startHour = course.StartTime.Split(
)[0];
startMinute = course.StartTime.Split(
)[1];
endHour = course.EndTime.Split(
endMinute = course.EndTime.Split(
// round hours and minutes
.Parse(startMinute) < 30)
.Parse(startMinute) < 15)
startMinute =
;
.Parse(startMinute) < 45)
startHour =
.Parse(startHour) + 1);
.Parse(endMinute) < 30)
.Parse(endMinute) < 15)
endMinute =
.Parse(endMinute) < 45)
endHour =
.Parse(endHour) + 1);
startTime = startHour +
+ startMinute;
endTime = endHour +
+ endMinute;
//original code color cell loop
//for (int i = ScheduleTypes.TimeDictionary[startTime]; i <= ScheduleTypes.TimeDictionary[endTime]; i++)
//this.DashboardGridContainer2.Rows[ScheduleTypes.WeekDayDictionary[course.day]].Cells[i].Style.BackColor = System.Drawing.Color.Blue;
//int count = DashboardGridContainer2.Rows.Count;
//for(int i = ScheduleTypes.TimeDictionary[startTime]; i <=count; i++)
.TimeDictionary[endTime]; i++)
//if (this.DashboardGridContainer2.DisplayLayout.Bands.FromKey("Section") != "M")
//if(this.DashboardGridContainer2.Columns.FromKey("Section".Substring(0,1).StartsWith!= "M"))
//this.DashboardGridContainer2.Rows[0].Cells.FromKey("Section");
//string cellsValue;
))
.Red;
.Blue;
//**************Color the grid******************************
.Green;
.White;
.WhiteSmoke;
//*****************End color grid***************************
////**********this is a test****************************
//for (int x = ScheduleTypes.TimeDictionary[startTime]; x <= ScheduleTypes.TimeDictionary[endTime]; x++)
// this.DashboardGridContainer2.Bands[12].CellClickAction = CellClickAction.CellSelect;
//added this code to test ***this makes the grid wider/bigger*************
//this.DashboardGridContainer2.DataKeys.ToString();
//this.DashboardGridContainer2.Columns.FromKey("Section").CellStyle.BackColor.A.ToString();
//********************************
//this fixes the width of the Weekdays
.Pixel(85);
//this fixes the width of the Times
.Pixel(47);
ex)
.WriteLine(ex.ToString());
how can I generate another grid but dynamically that will show the data depending on the "Room" value, if there are more than 2 "Rooms" geneate another datagrid?
please help
Hello,
If you want to create a dynamic grid, you will have to have some sort of a container (div/ tr etc.) that is run at server to add it to. Once you have a container, it is easy. Here is the code you will need at bare minimum.
dynamicGrid = new UltraWebGrid("DynamicGrid");dynamicGrid.DataSource = this.TestData();dynamicGrid.DataBind();this.MainContent.Controls.Add(dynamicGrid);
You will see that I create a grid, set its datasource, and then databind. Then, I add it to MainContent which in my case is a div which is runat=server.
That will get you a default grid on the screen. If you are using app styling in the application, the grid will automatically pick up those styles. If you are not, you will have to do some of these styles via code like dynamicGrid.DisplayLayout.RowAlternateStyleDefault = some style;
Also, one thing that I noticed. You are doing a lot of extra looping which is un necessary. for the row based settings, you can handle the Grids InitializeRow event. This will loop through each row of the grid, then you can make your check in there and set the row backcolor accordingly. you can also do it cell by cell if you want by going e.Row.Cells[0].Style.BackColor and loop through them all.
void dynamicGrid_InitializeRow(object sender, RowEventArgs e) { if (someCondition) { e.Row.Style.BackColor = Color.Blue; } }
Another thing that might be of use is the grids InitializeLayout Event. This is just a good location to put grid specific code like how you set the widths on columns. It is fired after binding the grid to its datasource.
If you want to use the same events on the dynamic grid, you can use the += syntax to add the event to the grid.
dynamicGrid.InitializeRow += new InitializeRowEventHandler(dynamicGrid_InitializeRow);
I hope this helps. Any questions please let me know.