private void SetTemplates() {
			foreach (DataControlField c in this.Columns) {
				if (c is CarrotHeaderSortTemplateField) {
					CarrotHeaderSortTemplateField ctf = (CarrotHeaderSortTemplateField)c;
					ctf.HeaderTemplate = new CarrotSortButtonHeaderTemplate(ctf.HeaderText, ctf.SortExpression);

					if (string.IsNullOrEmpty(ctf.DataField) && !string.IsNullOrEmpty(ctf.SortExpression)) {
						ctf.DataField = ctf.SortExpression;
					}

					if (ctf.ItemTemplate == null) {
						if (!string.IsNullOrEmpty(ctf.DataField) && !ctf.ShowBooleanImage && !ctf.ShowEnumImage) {
							ctf.ItemTemplate = new CarrotAutoItemTemplate(ctf.DataField, ctf.DataFieldFormat);
						}

						if (ctf.ShowBooleanImage && !ctf.ShowEnumImage) {
							CarrotBooleanImageItemTemplate iImageItemTemplate = new CarrotBooleanImageItemTemplate(ctf.DataField, ctf.BooleanImageCssClass);
							if (!string.IsNullOrEmpty(ctf.AlternateTextTrue) || !string.IsNullOrEmpty(ctf.AlternateTextFalse)) {
								iImageItemTemplate.SetVerbiage(ctf.AlternateTextTrue, ctf.AlternateTextFalse);
							}
							if (!string.IsNullOrEmpty(ctf.ImagePathTrue) || !string.IsNullOrEmpty(ctf.ImagePathFalse)) {
								iImageItemTemplate.SetImage(ctf.ImagePathTrue, ctf.ImagePathFalse);
							}
							ctf.ItemTemplate = iImageItemTemplate;
						}

						if (ctf.ShowEnumImage) {
							ctf.ItemTemplate = new CarrotImageItemTemplate(ctf.DataField, ctf.BooleanImageCssClass, ctf.ImageSelectors);
						}
					}
				}
			}
		}
Example #2
0
        protected string DoGrid(Control ctrl)
        {
            CarrotGridPaged myctrl = (CarrotGridPaged)ctrl;
            CarrotGridView theGrid = myctrl.TheGrid;

            Table table = new Table();
            table.CssClass = theGrid.CssClass;
            myctrl.Page.Controls.Add(table);

            TableHeaderRow trh = new TableHeaderRow();
            trh.CssClass = theGrid.HeaderStyle.CssClass;
            table.Rows.Add(trh);

            foreach (DataControlField col in theGrid.Columns) {
                TableHeaderCell thc = new TableHeaderCell();
                trh.Controls.Add(thc);
                thc.Text = col.HeaderText;
            }

            for (int r = 0; r < 5; r++) {
                TableRow tr = new TableRow();
                if (r % 2 == 0) {
                    tr.CssClass = theGrid.RowStyle.CssClass;
                } else {
                    tr.CssClass = theGrid.AlternatingRowStyle.CssClass;
                }
                table.Rows.Add(tr);

                foreach (DataControlField col in theGrid.Columns) {
                    TableCell tc = new TableCell();
                    tc.Text = " &nbsp; ";
                    tr.Controls.Add(tc);

                    if (col is BoundField) {
                        var bf = (BoundField)col;
                        tc.Text = bf.DataField;
                    }

                    if (col is TemplateField) {
                        var tf = (TemplateField)col;
                        try {
                            PlaceHolder ph = new PlaceHolder();
                            tc.Controls.Add(ph);
                            tf.ItemTemplate.InstantiateIn(ph);
                        } catch { }
                    }

                    if (col is CarrotHeaderSortTemplateField) {
                        var ctf = (CarrotHeaderSortTemplateField)col;
                        tc.Text = ctf.DataField;
                        try {
                            if (ctf.ShowBooleanImage || ctf.ShowEnumImage) {
                                PlaceHolder ph = new PlaceHolder();
                                tc.Controls.Add(ph);
                                CarrotBooleanImageItemTemplate imgTemplate = new CarrotBooleanImageItemTemplate(ctf.DataField, ctf.BooleanImageCssClass);
                                ctf.ItemTemplate = imgTemplate;
                                ctf.ItemTemplate.InstantiateIn(ph);
                            }
                        } catch { }
                    }
                }
            }

            return RenderCtrl(table);
        }