Example #1
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            string image = FileSource(false, cell);

            if (HyperLinkColumn && Grid.DisplayView == DisplayView.Grid)
            {
                string a = Grid.EnableCallBack ? Asynchronous.GetCallbackEventReference(Grid,
                                                                                        string.Format("RecordClick!{0}!{1}", ColumnId,
                                                                                                      cell.Row.PrimaryKeyValues),
                                                                                        false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                                                                                                              string.Format("RecordClick!{0}!{1}",
                                                                                                                                                                                            ColumnId,
                                                                                                                                                                                            cell.Row.
                                                                                                                                                                                            PrimaryKeyValues));

                string b = (String.IsNullOrEmpty(ConfirmMessage))
                               ? string.Empty
                               : String.Format("if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'"));

                image =
                    string.Format(
                        "<a class=\"wglinkfield\" href=\"#\" onclick=\"{0}{1}\">{2}</a>", b, a, image);
            }

            LabelHtml(image, writer, cell);
        }
Example #2
0
        /// <summary>
        /// Loads an empty (new) row from the database into the specified Table.
        /// <param name="table">The Table object to populate with empty data.</param>
        /// </summary>
        public static void GetEmptyData(Table table)
        {
            Row r = new Row(table);

            for (int i = 0; i < table.Columns.Count; i++)
            {
                RowCell c = new RowCell(table.Columns[i].ColumnId, r) {Row = r};
                if (table.Columns[i].ColumnType == ColumnType.ColumnTemplate)
                    c.Value = ((ColumnTemplate)table.Columns[i]).CreateCellControls;
                else if (c.Value == null && table.Columns[i].DefaultValue != null)
                    c.Value = table.Columns[i].DefaultValue;
                r.Cells.Add(c);
            }

            if (table.m_Grid.MasterWebGrid == null)
            {
                table.Rows.Add(r);
                return;
            }
            List<Column> masterWebGridPrimarykeys = table.m_Grid.MasterWebGrid.MasterTable.Columns.Primarykeys;

            int index = 0;

            while (index < masterWebGridPrimarykeys.Count)
            {
                string columnname = masterWebGridPrimarykeys[index].ColumnId;
                if (r.Columns.GetIndex(columnname) > -1)
                    r[columnname].Value = table.m_Grid.MasterWebGrid.MasterTable.Rows[0][columnname].Value;
                index++;
            }
            table.Rows.Add(r);
        }
Example #3
0
        // string optimize
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            string s = Value(cell);

            if (IsUrl && string.IsNullOrEmpty(s) == false && s.Length > 0)
            {
                //if( s.ToLowerInvariant() .StartsWith("http") == false )
                if (String.Compare(s, 0, "http", 0, 4, true) != 0)
                {
                    s = HTTPCONST + s;
                }
                s = ColumnGridAlias != null?string.Format(
                    "<a class=\"wglinkfield\" href=\"{0}\" target=\"_blank\">{1}</a>",
                    s, ColumnGridAlias) : string.Format("<a class=\"wglinkfield\" href=\"{0}\" target=\"_blank\">{1}</a>",
                                                        s, s);
            }
            if (IsEmail && !string.IsNullOrEmpty(s))
            {
                s = ColumnGridAlias != null?string.Format(
                    "<a class=\"wglinkfield\"  href=\"mailto:{0}\">{1}</a>",
                    s, ColumnGridAlias) : string.Format("<a class=\"wglinkfield\" href=\"mailto:{0}\"  >{1}</a>", s, s);
            }
            if (IsPassword && PasswordString != null)
            {
                s = PasswordString;
            }
            cell.Value = s;
            base.RenderLabelView(writer, cell);
        }
Example #4
0
 internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
 {
     if (cell.Value != null && Visibility != Visibility.None)
     {
         writer.Write(RenderTemplate(cell));
     }
 }
Example #5
0
        /// <summary>
        /// Validates this instance. (Returns always true)
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (!Equals(cell.Value, cell.DataSourceValue) && cell.Value is Boolean)
            {
                return(true);
            }
            if (!cell.GotPostBackData && (cell.Value != null && cell.Value is Boolean == false))
            {
                cell.PostBackValue = cell.Value.ToString();
            }
            if (string.IsNullOrEmpty(cell.PostBackValue))
            {
                return(true);
            }
            bool res;

            if (cell.PostBackValue.Equals(TrueValue))
            {
                cell.Value = true;
                return(true);
            }
            if (cell.PostBackValue.Equals(FalseValue))
            {
                cell.Value = false;
                return(true);
            }
            if (bool.TryParse(cell.PostBackValue, out res))
            {
                cell.Value = res;
                return(true);
            }
            return(false);
        }
Example #6
0
        /// <summary>
        /// Gets the name of the get storedfile.
        /// </summary>
        /// <value>The name of the get storedfile.</value>
        public string GetStoredfileName(RowCell cell)
        {
            string fileName;

            if (FileNameOption == FileNameOption.UsePrimaryKey && cell.Row[FileNameColumn].Value != null)
            {
                fileName =
                    string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId,
                                  GetExtension(cell.Row[FileNameColumn].Value.ToString()));
            }
            else if (FileNameColumn != null && cell.Row[FileNameColumn].Value != null)
            {
                fileName = cell.Row[FileNameColumn].Value.ToString();
            }
            else
            {
                if (IsBlob)
                {
                    return(null);
                }
                fileName = FileNameOption == FileNameOption.UsePrimaryKey
                               ? string.Format("{0}_{1}.{2}", cell.Row.PrimaryKeyUpdateValues, ColumnId, Value(cell))
                               : Value(cell);
            }
            return(fileName);
        }
Example #7
0
 private System.Drawing.Image CreateImageSizes(string filename, RowCell cell)
 {
     System.Drawing.Image img = null;
     if (FileTemporaryMode == FileTemporaryMode.File)
     {
         string tmpFile = HttpContext.Current.Session[string.Format("{0}_imgdata", cell.CellClientId)] as string;
         if (tmpFile != null)
         {
             img = System.Drawing.Image.FromFile(tmpFile);
         }
     }
     else // File in memory
     {
         img =
             (System.Drawing.Image)HttpContext.Current.Session[string.Format("{0}_imgdata", cell.CellClientId)];
     }
     if (ImageSizes != null && img != null)
     {
         for (int i = 0; i < ImageSizes.Count; i++)
         {
             string debugstr =
                 ImageSizes[i].Resize(img, AbsoluteDirectory, filename, cell);
             if (Grid.Debug)
             {
                 Grid.m_DebugString.AppendFormat("{0}<br/>", debugstr);
             }
         }
     }
     return(img);
 }
Example #8
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            bool res = base.Validate(cell);

            //	if(Value == null)
            //		IsInDataSource = false;
            return(res);
        }
Example #9
0
 internal new virtual string Value(RowCell cell)
 {
     if (cell.Value != null)
     {
         return(cell.Value.ToString());
     }
     return(null);
 }
Example #10
0
        internal override void GetColumnPostBackData(RowCell cell)
        {
            cell.GotPostBackData = true;

            if (Grid.GotHttpContext && HttpContext.Current.Request[cell.CellClientId] != null)
            {
                cell.Value = HttpContext.Current.Request[cell.CellClientId];
            }
        }
Example #11
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (!string.IsNullOrEmpty(Sum) && cell.Row.RowType == RowType.DataRow)
            {
                cell.Value = GetSum(cell);
            }

            base.RenderLabelView(writer, cell);
        }
Example #12
0
 internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
 {
     base.OnUpdateInsert(ea, cell);
     if (ea.IgnoreChanges)
     {
         return;
     }
     ea.AddApostrophe = false;
 }
Example #13
0
 private static bool SaveSession(string fileName, string tempFile, RowCell cell)
 {
     if (!Grid.GotHttpContext)
     {
         return(false);
     }
     HttpContext.Current.Session[cell.CellClientId + "_img"]     = fileName;
     HttpContext.Current.Session[cell.CellClientId + "_imgdata"] = tempFile;
     return(true);
 }
Example #14
0
        private static void DeleteSession(RowCell cell)
        {
            if (!Grid.GotHttpContext)
            {
                return;
            }

            HttpContext.Current.Session.Remove(cell.CellClientId + "_img");
            HttpContext.Current.Session.Remove(cell.CellClientId + "_imgdata");
        }
Example #15
0
 internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
 {
     if (AllowEdit == false)
     {
         RenderLabelView(writer, cell);
         return;
     }
     m_IsFormElement = false;
     RenderDetail(true, writer, cell);
 }
Example #16
0
        // private ITemplate m_Controls;



        #endregion

        #region Data handling


        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }
            const bool res = true;


            return(res);
        }
Example #17
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }

            if (!Equals(cell.Value, cell.DataSourceValue) && cell.Value is System.DateTime)
            {
                return(true);
            }
            if (!cell.GotPostBackData && (cell.Value != null && cell.Value is System.DateTime == false))
            {
                cell.PostBackValue = cell.Value.ToString();
            }
            bool res = base.Validate(cell);

            if (!res)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(cell.PostBackValue))
            {
                cell.Value = null;
                return(true);
            }

            System.DateTime result;
            if (
                !System.DateTime.TryParseExact(cell.PostBackValue, Format, CultureInfo.InvariantCulture,
                                               DateTimeStyles.None, out result))
            {
                if (string.IsNullOrEmpty(SystemMessage) == false)
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Grid_date"), Format),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Date"), Title, Format),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }
            cell.Value = result;
            return(true);
        }
Example #18
0
 void CorrectColumnsWidth(Rows rows)
 {
     for (int i = 0; i < rows.Count; i++)
     {
         Row row = rows[i];
         for (int j = 0; j < row.Count; j++)
         {
             RowCell rowCell = row[j];
             rowCell.ColumnWidth = new GridLength(rowCell.ActualWidth / row.RowWidth, GridUnitType.Star);
         }
     }
 }
Example #19
0
        internal override void GetColumnPostBackData(RowCell cell)
        {
            if (cell.GotPostBackData || !Grid.GotHttpContext)
            {
                return;
            }
            // Gets the posted file and saves it to a temporary image.
            // Updates views tate saying that the file needs to be renamed
            using (HtmlInputFile f = new HtmlInputFile())
            {
                f.ID = cell.CellClientId;

                if (f.PostedFile == null || f.PostedFile.FileName.Length == 0)
                {
                    return;
                }
                if (AllowExtension(f.PostedFile.FileName) == false)
                {
                    Grid.SystemMessage.Add("You are not allowed to upload files of this type.",
                                           SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    return;
                }

                string fileName = Path.GetFileName(f.PostedFile.FileName);

                // We must set the filename column before we do any stuff
                if (FileNameColumn != null)
                {
                    cell.Row[FileNameColumn].Value = fileName;
                }

                if (FileTemporaryMode == FileTemporaryMode.File)
                {
                    string tempFile = Path.GetTempFileName();
                    f.PostedFile.SaveAs(tempFile);
                    if (SaveSession(fileName, tempFile, cell) == false)
                    {
                        return;
                    }
                }
                else
                {
                    if (SaveSession(fileName, f.PostedFile.InputStream, cell) == false)
                    {
                        return;
                    }
                }

                cell.Value           = fileName;
                cell.GotPostBackData = true;
            }
        }
Example #20
0
        internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
        {
            base.OnUpdateInsert(ea, cell);
            if (ea.IgnoreChanges)
            {
                return;
            }

            if (EncryptionKey != null && ea.Value != null) // Decrypt ?
            {
                ea.Value = Security.Encrypt(ea.Value.ToString(), EncryptionKey);
            }
        }
Example #21
0
        // 2005.01.09 - jorn, string optimize
        internal override void GetColumnPostBackData(RowCell cell)
        {
            try
            {
                string uniqueID = cell.CellClientId;
                if (Grid.GotHttpContext && HttpContext.Current.Request.Form[uniqueID] != null)
                {
                    cell.GotPostBackData = true;
                    cell.PostBackValue   = HttpContext.Current.Request.Form[uniqueID];
                    if (cell.PostBackValue == string.Empty)
                    {
                        cell.PostBackValue = null;
                        cell.Value         = null;
                    }
                    else
                    {
                        cell.Value = cell.PostBackValue;
                    }
                    Grid.State(uniqueID, cell.PostBackValue);
                }
                else
                {
                    if (!string.IsNullOrEmpty(Table.DataSourceId) &&
                        (Table.Columns == null || Table.Columns.Primarykeys.Count == 0))
                    {
                        throw new GridException(string.Format(
                                                    "No Primarykey was detected for foreign key column '{0}'.", Title));
                    }
                    // Check if we are using a mastergrid;
                    bool t1 = Grid.MasterWebGrid != null;

                    // Are we in detail view?
                    bool t3 = (Grid.DisplayView == DisplayView.Detail);

                    // Are we in insert-mode, not update-mode?
                    bool t6 = (Grid.InternalId == null);

                    bool t5 = cell.Value == null;

                    // Auto fill in
                    if (t1 && t3 && t5 && t6)
                    {
                        cell.Value = Grid.MasterWebGrid.InternalId;
                    }
                }
            }
            catch (Exception ee)
            {
                throw new GridException(string.Format("Error getting post back-data for foreign key '{0}' in Grid '{1}'", ColumnId, Grid.ID), ee);
            }
        }
Example #22
0
        internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (Identity || AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
            {
                RenderLabelView(writer, cell);
                return;
            }

            if (Sum != null && cell.Row.RowType == RowType.DataRow)
            {
                decimal?unusedVar = GetSum(cell);
            }
            base.RenderEditView(writer, cell);
        }
Example #23
0
 /// <summary>
 /// Display Value for number Columns
 /// </summary>
 public override string DisplayText(RowCell cell)
 {
     if (!Equals(cell.Value, cell.DataSourceValue) || cell.PostBackValue == null)
     {
         if (!Value(cell))
         {
             return(FalseValue);
         }
         else if (Value(cell))
         {
             return(TrueValue);
         }
     }
     return(cell.PostBackValue);
 }
Example #24
0
        /// <summary>
        /// Validates a postback value for this column.
        /// </summary>
        /// <param name="cell">The cell with postback value</param>
        /// <returns>returns null if failed to validate else the column object type</returns>
        public override object ValidateColumnPostBackValue(RowCell cell)
        {
            if (string.IsNullOrEmpty(cell.PostBackValue))
            {
                return(null);
            }
            System.DateTime result;

            if (!System.DateTime.TryParseExact(cell.PostBackValue, Format, Grid.Culture,
                                               DateTimeStyles.None, out result))
            {
                return(null);
            }
            return(result);
        }
Example #25
0
        // 2005.01.09 - jorn, string optimize
        internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
        {
            // Fix value
            ea.AddApostrophe = true;

            // If update and value matches with DB then don't update
            if (ea.Value != null && ea.Value.Equals(cell.DataSourceValue))
            {
                ea.IgnoreChanges = true;
            }

            if (ea.Value == null)
            {
                ea.AddApostrophe = false;
            }
        }
Example #26
0
        void PrepareColumns(Rows rows)
        {
            int counter = 0;

            for (int i = 0; i < rows.Count; i++)
            {
                Row row = rows[i];
                for (int j = 0; j < row.Count; j++)
                {
                    RowCell rowCell = row[j];
                    Canvas.SetZIndex(rowCell.GridColumnPresenter, counter);
                    rowCell.GridColumn.VisibleIndex = counter;
                    counter++;
                }
            }
        }
Example #27
0
        /// <summary>
        /// Gets the items in the Many-to-Many collection.
        /// </summary>
        /// <value>The items.</value>
        public ManyToManyCollection LoadItems(RowCell cell)
        {
            GetColumnPostBackData(cell);
            EnsureItems(cell);

            if ((Value(cell) != null))
            {
                foreach (string item in Value(cell).ToString().Split(','))
                {
                    if (Items[item] != null)
                    {
                        Items[item].Checked = true;
                    }
                }
            }
            return(Items);
        }
Example #28
0
        internal override void GetColumnPostBackData(RowCell cell)
        {
            if (cell.GotPostBackData || !Grid.GotHttpContext)
            {
                return;
            }
            cell.GotPostBackData = true;
            string uniqueID = cell.CellClientId;

            // Check if we have a post back, need this since checkbox "returns null" both for unchecked and non-existing
            if (HttpContext.Current.Request[uniqueID + "_cb"] == null)
            {
                return;
            }

            cell.PostBackValue = HttpContext.Current.Request[uniqueID] ?? FalseValue;
        }
Example #29
0
        private void OnUpdateInsertDataSource(CellUpdateInsertArgument ea, RowCell cell)
        {
            if (!Grid.GotHttpContext)
            {
                return;
            }
            if (HttpContext.Current.Session[cell.CellClientId + "_imgdata"] == null)
            {
                ea.IgnoreChanges = true;
                return;
            }
            BinaryReader br;

            switch (FileTemporaryMode)
            {
            case FileTemporaryMode.Memory:

                System.Drawing.Image img = (System.Drawing.Image)HttpContext.Current.Session[cell.CellClientId + "_imgdata"];

                //if (Sizes.Count > 0)
                //    img = Sizes[0].Resize(img);

                MemoryStream ms = new MemoryStream();
                img.Save(ms, img.RawFormat);
                br = new BinaryReader(ms);

                br.BaseStream.Position = 0;
                ea.Parameter           = br;
                ea.IgnoreChanges       = false;
                break;

            case FileTemporaryMode.File:
            {
                FileStream fs =
                    System.IO.File.Open((string)HttpContext.Current.Session[cell.CellClientId + "_imgdata"],
                                        FileMode.Open, FileAccess.Read, FileShare.Read);
                br = new BinaryReader(fs);
                fs.Close();
                br.BaseStream.Position = 0;
                ea.Parameter           = br;
                ea.IgnoreChanges       = false;
            }
            break;
            }
        }
Example #30
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
            {
                return(true);
            }

            if (!Equals(cell.Value, cell.DataSourceValue))
            {
                cell.PostBackValue = cell.Value != null?cell.Value.ToString() : null;
            }

            if (string.IsNullOrEmpty(cell.PostBackValue) /*|| cell.PostBackValue == Grid.NULLCONSTANT*/)
            {
                if (AllowEmpty && Required == false)
                {
                    return(true); // no further checking necessary
                }
                if (string.IsNullOrEmpty(SystemMessage) == false)
                {
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                }
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                {
                    Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_required")),
                                           SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                else
                {
                    string title = Title;
                    if (string.IsNullOrEmpty(title))
                    {
                        title = ColumnId;
                    }
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Required"), title),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return(false);
            }
            cell.Value = cell.PostBackValue;

            return(true);
        }
Example #31
0
        // 2005.01.09 - jorn, string optimize, String.Compare
        internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
            {
                RenderLabelView(writer, cell);
                return;
            }

            base.RenderEditView(writer, cell);

            if (DisplayCalendar && Grid.GotHttpContext)
            {
                Grid.AddClientScript(writer, string.Format(calendarsetup, cell.CellClientId,
                                                           CalendarFormat, AddCalendarClientAttributes,
                                                           Grid.Page.ClientScript.GetWebResourceUrl(Grid.GetType(),
                                                                                                    "WebGrid.Resources.images.calendar.gif")));
            }
        }
Example #32
0
        internal void EditHtml(string text, HtmlTextWriter writer,RowCell cell)
        {
            string systemMessage = null;
            if (cell.Row != null && Grid.SystemMessage[cell.Row.GetColumnInitKeys(ColumnId)] != null)
                systemMessage = Grid.SystemMessage[cell.Row.GetColumnInitKeys(ColumnId)].Message;

            if (TreeLevel > 0 && Grid.DisplayView == DisplayView.Grid)
            {
                StringBuilder indent = new StringBuilder(string.Empty);
                for (int i = 0; i < TreeLevel; i++)
                    indent.Append(TreeIndentText);
                writer.Write("<span class=\"wgnowrap\">");
                writer.Write(indent);
            }

            if (string.IsNullOrEmpty(PreDetailText) == false && m_Grid.DisplayView == DisplayView.Detail)
                writer.Write(PreDetailText);
            if (string.IsNullOrEmpty(PreGridText) == false && m_Grid.DisplayView == DisplayView.Grid)
                writer.Write(PreGridText);

            if (systemMessage != null && (SystemMessageStyle == SystemMessageStyle.WebGrid) == false)
            {
                string jqueryuicss = "";
                if (m_Grid.IsUsingJQueryUICSSFramework)
                    jqueryuicss = "ui-state-error-text ";
                switch (SystemMessageStyle)
                {
                    case SystemMessageStyle.ColumnLeft:
                        writer.Write("<div class=\"{1}wgsystemmessagetitle\">{0}</div>", systemMessage, jqueryuicss);
                        break;
                    case SystemMessageStyle.ColumnTop:
                        writer.Write("<div class=\"{1}wgsystemmessagetitle\">{0}</div><br/>", systemMessage, jqueryuicss);
                        break;
                }
            }
             /*  if (m_GridViewTemplate != null && m_Grid.DisplayView == DisplayView.Grid)
                writer.Write(RenderGridViewTemplate(cell));
            else if (m_DetailViewTemplate != null && m_Grid.DisplayView == DisplayView.Detail)
                writer.Write(RenderDetailViewTemplate(cell));
            else*/
                writer.Write(text);

            if (systemMessage != null && (SystemMessageStyle == SystemMessageStyle.WebGrid) == false)
            {
                string jqueryuicss = "";
                if (m_Grid.IsUsingJQueryUICSSFramework)
                    jqueryuicss = "ui-state-error-text ";
                switch (SystemMessageStyle)
                {
                    case SystemMessageStyle.ColumnRight:
                        writer.Write("<div class=\"wgsystemmessagetitle\">{0}</div>", systemMessage, jqueryuicss);
                        break;
                    case SystemMessageStyle.ColumnBottom:
                        writer.Write("<br/><div class=\"wgsystemmessagetitle\">{0}</div>", systemMessage, jqueryuicss);
                        break;
                }
            }
            if (TreeLevel > 0 && Grid.DisplayView == DisplayView.Grid)
                writer.Write("</span>");
            if (string.IsNullOrEmpty(PostDetailText) == false && m_Grid.DisplayView == DisplayView.Detail)
                writer.Write(PostDetailText);
            else if (string.IsNullOrEmpty(PostGridText) == false && m_Grid.DisplayView == DisplayView.Grid)
                writer.Write(PostGridText);
        }
Example #33
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
                return true;

            if (!Equals(cell.Value, cell.DataSourceValue))
                cell.PostBackValue = cell.Value != null ? cell.Value.ToString() : null;

            if (string.IsNullOrEmpty(cell.PostBackValue) /*|| cell.PostBackValue == Grid.NULLCONSTANT*/)
            {
                if (AllowEmpty && Required == false)
                    return true; // no further checking necessary
                if (string.IsNullOrEmpty(SystemMessage) == false)
                    Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                           cell.Row.GetColumnInitKeys(ColumnId));
                else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                    Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_required")),
                                           SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                else
                {
                    string title = Title;
                    if (string.IsNullOrEmpty(title))
                        title = ColumnId;
                    Grid.SystemMessage.Add(
                        String.Format(Grid.GetSystemMessage("SystemMessage_Required"), title),
                        SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                }
                return false;
            }
            cell.Value = cell.PostBackValue;

            return true;
        }
Example #34
0
        internal void LoadValueFromColumnDataSource(RowCell cell)
        {
            if (!m_LoadColumnDataSourceData)
                return;
            if (string.IsNullOrEmpty(DataSourcePrimaryKeys))
                throw new GridException(
                    string.Format(
                        "Set the 'DataSourcePrimaryKeys' for the property 'LoadColumnDataSourceData' in the column '{0}'",
                        ColumnId));

            string where = BuildColumnDataSourceIdFilter(cell.Row, DataSourcePrimaryKeys.Split(';'));
            cell.Value =
                Query.ExecuteScalar(string.Format("SELECT {2} FROM [{0}] WHERE {1}", DataSourceId, where, ColumnId),
                                    m_Grid.ActiveConnectionString);
            cell.DataSourceValue = cell.Value;
            if (Grid.Trace.IsTracing)
                Grid.Trace.Trace("LoadValueFromColumnDataSource - {3}.{2}:  SELECT {2} FROM [{0}] WHERE {1}", DataSourceId, where, ColumnId,Grid.ID);
        }
Example #35
0
 internal virtual void RenderLabelView(HtmlTextWriter writer,RowCell cell)
 {
     m_IsFormElement = false;
     RenderGrid(DisplayText(cell), writer, cell);
 }
Example #36
0
        internal override void RenderLabelView(HtmlTextWriter writer, RowCell cell)
        {
            if (cell.Value != null && !string.IsNullOrEmpty(ValueColumn))
            {
                RowCollection row = Table.Rows;
                string value = cell.Value.ToString();
                for (int i = 0; i < row.Count; i++)
                {
                    if (!string.IsNullOrEmpty(IdentityColumn) && Table.Rows[i][IdentityColumn].Value != null)
                    {
                        if (Table.Rows[i][IdentityColumn].Value.ToString() != value)
                            continue;
                    }
                    else if (row[i].PrimaryKeyUpdateValues != value)
                        continue;
                    cell.Value = BuildDisplayText(i, ValueColumn, Table);
                    break;
                }
            }
            if (cell.Value == null)
                cell.Value = string.Empty;

            string s = cell.Value.ToString();

            if (string.IsNullOrEmpty(TreeStructureSeperator) == false && TreeParentId != null)
            {
                string text = string.Empty;
                RenderEntireTreeList(ref text, cell.Value, 0);
                if (string.IsNullOrEmpty(text) == false)
                    s = text + TreeStructureSeperator + s;
            }
            RenderGrid(s, writer, cell);
        }
Example #37
0
        // 2005.01.09 - jorn, string optimize
        private string CreateSelectRows(bool tree, string parentValue, int level, RowCell cell)
        {
            StringBuilder s = new StringBuilder(string.Empty);
            bool m_Foreignkeyselected = false;
            for (int i = 0; i < Table.Rows.Count; i++)
            {

                string optionValue = Table.Rows[i].PrimaryKeyValues;

                if (!string.IsNullOrEmpty(IdentityColumn) && Table.Rows[i][IdentityColumn].Value != null)
                    optionValue = Table.Rows[i][IdentityColumn].Value.ToString();

                if (tree)
                {
                    string treeValue = null;

                    if (Table.Rows[i][TreeParentId].Value != null)
                        treeValue = Table.Rows[i][TreeParentId].Value.ToString();
                    if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(optionValue))
                        continue;
                }

                string selected = string.Empty;

                if (!m_Foreignkeyselected && optionValue != null)
                {
                    if (cell.PostBackValue != null)
                        selected = Equals(optionValue, cell.PostBackValue)
                                       ? " selected=\"selected\" "
                                       : string.Empty;
                    else if (cell.Value != null)
                        selected = Equals(optionValue, cell.Value.ToString()) ? " selected=\"selected\" " : string.Empty;
                    else if (RememberState && string.IsNullOrEmpty(selected) &&
                             (string)Grid.GetState(cell.CellClientId) != null)
                    {
                        selected =
                            (String.Compare(optionValue, Grid.GetState(cell.CellClientId) as string, true) == 0)
                                ? "selected=\"selected\" "
                                : string.Empty;
                    }
                    if (string.IsNullOrEmpty(selected) == false)
                        m_Foreignkeyselected = true;
                }
                StringBuilder optionText = new StringBuilder(string.Empty);
                if (level > 0)
                    for (int j = 0; j < level; j++)
                        optionText.Append(TreeIndentText);
                try
                {
                    optionText.Append(BuildDisplayText(i, ValueColumn, Table));
                }
                catch (Exception e)
                {
                    throw new GridException(
                        string.Format("Error creating select rows for foreign keys ({0})", ColumnId), e);
                }
                //	if( _enableOnlyTreeLeaf && IsEndLeaf(optionValue) == false )
                //		s += "<option " + selected + "value=\"" + optionValue + "\">" + optionText;
                //	else
                s.AppendFormat("<option{0} value=\"{1}\">{2}</option>", selected, optionValue, optionText);
                if (tree)
                    s.Append(CreateSelectRows(true, optionValue, level + 1, cell));
            }
            return s.ToString();
        }
Example #38
0
        internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (Identity || AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
            {
                RenderLabelView(writer, cell);
                return;
            }

            if (Sum != null && cell.Row.RowType == RowType.DataRow)
            {
                decimal? unusedVar = GetSum(cell);
            }
            base.RenderEditView(writer, cell);
        }
Example #39
0
        // 2005.01.09 - jorn, string optimize
        internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
        {
            // Fix value
            ea.AddApostrophe = true;

            // If update and value matches with DB then don't update
            if (ea.Value != null && ea.Value.Equals(cell.DataSourceValue))
                ea.IgnoreChanges = true;

            if (ea.Value == null)
                ea.AddApostrophe = false;
        }
Example #40
0
        internal decimal GetSum(RowCell cell)
        {
            if (Sum == null)
                return m_GetColumnSum;
            string mathExpression = Sum.ToLowerInvariant();
            if (Grid.Trace.IsTracing)
                Grid.Trace.Trace("Starting getting data for math. ({0})", ColumnId);
            ColumnCollection columns = m_Table.Columns;
            foreach (Column column in columns)
            {
                if (mathExpression.IndexOf(string.Format("[{0}]", column.ColumnId), StringComparison.OrdinalIgnoreCase) == -1)
                    continue;
                if (cell.Row[column.ColumnId].Value == null || cell.Row[column.ColumnId].Value == DBNull.Value)
                    mathExpression = mathExpression.Replace(string.Format("[{0}]", column.ColumnId.ToLowerInvariant()),
                                                            "0");
                else
                {
                    object myValue = cell.Row[column.ColumnId].Value;
                    if (myValue != null)
                        mathExpression =
                            mathExpression.Replace(string.Format("[{0}]", column.ColumnId.ToLowerInvariant()),
                                                   myValue.ToString().Replace(",", "."));
                    else
                        mathExpression = "";
                }
            }
            try
            {
                if (Grid.Trace.IsTracing)
                    Grid.Trace.Trace("Ended getting data for math. ({0})", ColumnId);

                m_GetColumnSum = Convert.ToDecimal(Evaluate(mathExpression));
                TotalSum = TotalSum + m_GetColumnSum;
                if (Grid.Trace.IsTracing)
                    Grid.Trace.Trace("Successfully calculating expression: {0} = {1} (Total: {2})", mathExpression,
                                     m_GetColumnSum.ToString(Format, Grid.Culture), TotalSum);
            }
            catch (Exception ee)
            {
                throw new GridException(
                    string.Format("Error calculating expression: {0} for columnId: {1}", mathExpression, ColumnId), ee);
            }
            return m_GetColumnSum;
        }
Example #41
0
 internal override void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
 {
     base.OnUpdateInsert(ea, cell);
     if (ea.IgnoreChanges) return;
     ea.AddApostrophe = false;
 }
Example #42
0
        /// <summary>
        /// Validates a postback value for this column.
        /// </summary>
        /// <param name="cell">The cell with postback value</param>
        /// <returns>returns null if failed to validate else the column object type</returns>
        public override object ValidateColumnPostBackValue(RowCell cell)
        {
            if (string.IsNullOrEmpty(cell.PostBackValue))
                return null;

            string myValue = Grid.m_Whitespaceregexp.Replace(cell.PostBackValue, string.Empty);
            decimal f;
            if (!decimal.TryParse(myValue,
                                  NumberStyles.Any | NumberStyles.AllowTrailingWhite |
                                  NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite |
                                  NumberStyles.AllowTrailingWhite, Grid.Culture,
                                  out f) == false)
                return null;
            return f;
        }
Example #43
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <returns></returns>
        public override bool Validate(RowCell cell)
        {
            if (DenyValidate())
                return true;

            if (!Equals(cell.Value, cell.DataSourceValue) && cell.Value is System.Decimal)
                return true;
            if (!cell.GotPostBackData && (cell.Value != null && cell.Value is System.Decimal == false))
                cell.PostBackValue = cell.Value.ToString();

            bool res = base.Validate(cell);

            if (res)
            {
                if (!string.IsNullOrEmpty(cell.PostBackValue))
                {
                    string myValue = Grid.m_Whitespaceregexp.Replace(cell.PostBackValue, string.Empty);
                    decimal f;
                    if (!decimal.TryParse(myValue,
                                         NumberStyles.Any | NumberStyles.AllowTrailingWhite |
                                         NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite |
                                         NumberStyles.AllowTrailingWhite, Grid.Culture,
                                         out f))
                    {
                        if (!string.IsNullOrEmpty(SystemMessage))
                            Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                                   cell.Row.GetColumnInitKeys(ColumnId));
                        else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                            Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Grid_dec")),
                                                   SystemMessageStyle,
                                                   cell.Row.GetColumnInitKeys(ColumnId));
                        else
                            Grid.SystemMessage.Add(String.Format(Grid.GetSystemMessage("SystemMessage_Dec"), Title),
                                                   SystemMessageStyle,
                                                   cell.Row.GetColumnInitKeys(ColumnId));
                        res = false;
                    }
                    else
                        cell.Value = f;
                }
                else
                    cell.Value = null;
            }
            else
                return false;

            if (Value(cell) != null)
            {
                if (MaxSize != 0 && Value(cell) > MaxSize)
                {

                    if (!String.IsNullOrEmpty(SystemMessage))
                        Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                               cell.Row.GetColumnInitKeys(ColumnId));
                    else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                        Grid.SystemMessage.Add(
                            string.Format("Maximum allowed value is {0}.", MaxSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle,
                            cell.Row.GetColumnInitKeys(ColumnId));
                    else
                        Grid.SystemMessage.Add(
                            string.Format("Maximum allowed value for '{0}' is {1}.", Title,
                                          MaxSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    return false;
                }

                if (MinSize != 0 && Value(cell) < MinSize)
                {
                    if (!String.IsNullOrEmpty(SystemMessage))
                        Grid.SystemMessage.Add(SystemMessage, SystemMessageStyle,
                                               cell.Row.GetColumnInitKeys(ColumnId));
                    else if (Grid.DisplayView == DisplayView.Grid && SystemMessageStyle != SystemMessageStyle.WebGrid)
                        Grid.SystemMessage.Add(
                            string.Format("Minimum allowed value is {0}.", MinSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle,
                            cell.Row.GetColumnInitKeys(ColumnId));
                    else
                        Grid.SystemMessage.Add(
                            string.Format("Minimum allowed value for '{0}' is {1}.", Title,
                                          MinSize.ToString(Format, Grid.Culture)),
                            SystemMessageStyle, cell.Row.GetColumnInitKeys(ColumnId));
                    return false;
                }
            }

            return res;
        }
Example #44
0
 /// <summary>
 /// Display Value for decimal column
 /// </summary>
 public override string DisplayText(RowCell cell)
 {
     if (!Equals(cell.Value, cell.DataSourceValue) || cell.PostBackValue == null)
         if (Value(cell) != null)
             return ((System.Decimal)cell.Value).ToString(Format, Grid.Culture);
         else if (cell.Value != null) return cell.Value.ToString();
         else return DefaultValue;
     return cell.PostBackValue;
 }
Example #45
0
 internal static object GetApostropheValue(RowCell cell)
 {
     return (cell.Value == null || cell.Value is int) ? cell.Value : string.Format("'{0}'", cell.Value);
 }
Example #46
0
 internal void Render(HtmlTextWriter writer, RowCell cell)
 {
     if (cell.Row.CellsToSpan > 0)
         cell.Row.CellsToSpan--;
     else
     {
         if (cell.ExtraCellSpan > 0)
             cell.Row.CellsToSpan += cell.ExtraCellSpan;
         if (Grid.DisplayView == DisplayView.Grid)
             DesignRenderGrid(writer, cell);
         else
             DesignRenderDetail(writer, cell);
     }
 }
Example #47
0
        // 2005.01.09 - jorn, string optimize
        internal override void GetColumnPostBackData(RowCell cell)
        {
            try
            {
                string uniqueID = cell.CellClientId;
                if (Grid.GotHttpContext && HttpContext.Current.Request.Form[uniqueID] != null)
                {
                    cell.GotPostBackData = true;
                    cell.PostBackValue = HttpContext.Current.Request.Form[uniqueID];
                    if (cell.PostBackValue == string.Empty)
                    {
                        cell.PostBackValue = null;
                        cell.Value = null;
                    }
                    else
                        cell.Value = cell.PostBackValue;
                    Grid.State(uniqueID, cell.PostBackValue);
                }
                else
                {
                    if (!string.IsNullOrEmpty(Table.DataSourceId) &&
                        (Table.Columns == null || Table.Columns.Primarykeys.Count == 0))
                        throw new GridException(string.Format(
                                                    "No Primarykey was detected for foreign key column '{0}'.", Title));
                    // Check if we are using a mastergrid;
                    bool t1 = Grid.MasterWebGrid != null;

                    // Are we in detail view?
                    bool t3 = (Grid.DisplayView == DisplayView.Detail);

                    // Are we in insert-mode, not update-mode?
                    bool t6 = (Grid.InternalId == null);

                    bool t5 = cell.Value == null;

                    // Auto fill in
                    if (t1 && t3 && t5 && t6)
                        cell.Value = Grid.MasterWebGrid.InternalId;

                }
            }
            catch (Exception ee)
            {
                throw new GridException(string.Format("Error getting post back-data for foreign key '{0}' in Grid '{1}'", ColumnId, Grid.ID), ee);
            }
        }
Example #48
0
        /*

        /// <summary>
        /// HTML Template for WebGrid Columns, if set it will render the content of this instead of the Value of the content.
        /// Create dynamic content by referring to columnId surrounded by [ and ] an example of dynamic content is:
        /// "Hi my first name is [FirstName]"
        /// </summary>
        /// <value>The html content</value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [TemplateInstance(TemplateInstance.Single)]
        [DefaultValue(null)]
        [Browsable(false)]
        [MergableProperty(false)]
        [NotifyParentProperty(true)]
        public PlaceHolder GridViewTemplate
        {
            get
            {
                if (m_GridViewTemplate == null)
                    m_GridViewTemplate = new PlaceHolder();
                return m_GridViewTemplate;
            }
            set
            {
                m_GridViewTemplate = value;

            }
        }

        private PlaceHolder m_GridViewTemplate;
        private string  m_GridViewTemplateCache;

        /// <summary>
        /// HTML Template for WebGrid Columns, if set it will render the content of this instead of the Value of the content.
        /// Create dynamic content by referring to columnId surrounded by [ and ] an example of dynamic content is:
        /// "Hi my first name is [FirstName]"
        /// </summary>
        /// <value>The html content</value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [TemplateInstance(TemplateInstance.Single)]
        [DefaultValue(null)]
        [Browsable(false)]
        [MergableProperty(false)]
        [NotifyParentProperty(true)]
        public PlaceHolder DetailViewTemplate
        {
            get
            {
                if (m_DetailViewTemplate == null)
                    m_DetailViewTemplate = new PlaceHolder();
                return m_DetailViewTemplate;
            }
            set
            {
                m_DetailViewTemplate = value;

            }
        }

        private PlaceHolder m_DetailViewTemplate;
        private string m_DetailViewTemplateCache;
        */
        internal object Value(RowCell cell)
        {
            LoadValueFromColumnDataSource(cell);
            return cell.Value;
        }
Example #49
0
        internal override void RenderEditView(HtmlTextWriter writer, RowCell cell)
        {
            if (Table.m_GotData == false) // Data need to be recovered if CacheDatasourceStructure is active.
                Table.GetData(true);

            if (Identity || AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
            {
                RenderLabelView(writer, cell);
                return;
            }

            if (string.IsNullOrEmpty(ValueColumn))
                throw new GridException(
                    String.Format(Table.m_Grid.GetSystemMessage("SystemMessage_ForeignkeyNoValueColumn"), Title));

            StringBuilder s = new StringBuilder(string.Empty);

            switch (ForeignkeyType)
            {
                case ForeignkeyType.Select:
                case ForeignkeyType.SelectMenu:
                    {
                        StringBuilder eventScript = new StringBuilder(string.Empty);
                        StringBuilder javascript = new StringBuilder(string.Empty);
                        if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false)
                        {
                            eventScript = new StringBuilder(" onchange=\"");
                            if (string.IsNullOrEmpty(ConfirmMessage) == false)
                                eventScript.AppendFormat(" if(wgconfirm('{0}',this,'{1}')) ",
                                                         ConfirmMessage.Replace("'", "\\'"),
                                                         Grid.DialogTitle.Replace("'", "\\'"));
                            string link = Grid.EnableCallBack && !ForcePostBack
                                              ? Asynchronous.GetCallbackEventReference(Grid,
                                                                                       string.Format(
                                                                                           "ElementPostBack!{0}!{1}",
                                                                                           ColumnId,
                                                                                           cell.Row.PrimaryKeyValues),
                                                                                       false,
                                                                                       string.Empty,
                                                                                       string.Empty)
                                              : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                                 string.Format(
                                                                                                     "ElementPostBack!{0}!{1}",
                                                                                                     ColumnId,
                                                                                                     cell.Row.
                                                                                                         PrimaryKeyValues));
                            eventScript.AppendFormat("{0}\"", link);
                        }

                        StringBuilder onblur = new StringBuilder(" onblur=\"");

                        if (Grid.ColumnChangedColour != Color.Empty)
                            onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour));
                        onblur.Append("\"");
                        javascript.Append(onblur);
                        s.AppendFormat("<select {0} class=\"wgeditfield wgselectbox {4}\" id=\"{1}\" name=\"{1}\" {2} {3}>",
                                       javascript, cell.CellClientId, eventScript, Attributes,CssClass);
                        if (m_Foreignkeytype == ForeignkeyType.SelectMenu && ( Grid.Scripts == null || !Grid.Scripts.DisableSelectMenu))
                            if (SelectMenuWidth > 0)
                                Grid.AddClientScript(writer,
                                                     string.Format(
                                                         "$(document).ready(function() {{$('#{0}').selectmenu({{maxHeight: {2},style:'dropdown',width: {1}}});}});",
                                                         cell.CellClientId, SelectMenuWidth, SelectMenuMaxHeight));
                            else
                                Grid.AddClientScript(writer,
                                                     string.Format(
                                                         "$(document).ready(function() {{$('#{0}').selectmenu({{maxHeight: {1},style:'dropdown'}});}});",
                                                         cell.CellClientId, SelectMenuMaxHeight));

                        if (Table.Rows.Count == 0 && NullText == null)
                            NullText = "No data available.";

                        if (NullText != null)
                            s.AppendFormat("<option value=\"{1}\">{0}</option>", NullText, string.Empty);

                        //CreateRows(Grid,tree,null,0);

                        s.Append(CreateSelectRows(TreeParentId != null, null, 0, cell));
                        s.Append("</select>");
                    }
                    break;
                case ForeignkeyType.Radiobuttons:
                    m_IsFormElement = false;
                    m_Rowcounter = RecordsPerRow;
                    s.AppendFormat("<table class=\"wgradiobuttons {1}\"><tr><td>{0}</td></tr></table>",
                                   CreateRadioButtons((TreeParentId != null), null, 0, cell),CssClass);
                    break;
            }

            if (string.IsNullOrEmpty(ToolTipInput) == false)
                s = new StringBuilder(Tooltip.Add(s.ToString(), ToolTipInput));

            EditHtml(s.ToString(), writer, cell);
        }
Example #50
0
        internal void RenderGrid(object strValue, HtmlTextWriter writer,RowCell cell)
        {
            if (strValue == null)
            {
                LabelHtml(null, writer, cell);
                return;
            }

            object theValueToShow = strValue;
            if (HtmlEncode)
                theValueToShow = HttpUtility.HtmlEncode(theValueToShow.ToString());

            string s = theValueToShow.ToString();

            if (Grid.DisplayView == DisplayView.Grid)
            {
                if (TextTruncate > 0 && s.Length > TextTruncate)
                {
                    string[] words = s.Split(' ');
                    if (words.Length == 1)
                    {
                        s = string.Format("{0} <b>..</b>", s.Substring(0, TextTruncate));
                        if (m_HyperLinkColumn == null)
                            HyperLinkColumn = true;
                    }
                    else
                    {
                        StringBuilder truncatedmsgBuilder = new StringBuilder();

                        for (int i = 0; i < words.Length; i++)
                        {
                            if (i == 0 && words[i].Length > TextTruncate)
                            {
                                s = string.Format("{0} <b>..</b>", words[i].Substring(0, TextTruncate));
                                if (m_HyperLinkColumn == null)
                                    HyperLinkColumn = true;
                                break;
                            }
                            if ((truncatedmsgBuilder.Length + words[i].Length) > TextTruncate)
                            {
                                s = string.Format("{0} <b>..</b>", truncatedmsgBuilder);
                                if (m_HyperLinkColumn == null)
                                    HyperLinkColumn = true;
                                break;
                            }
                            truncatedmsgBuilder.AppendFormat(" {0}", words[i]);
                        }
                    }
                }
                if (HyperLinkColumn)
                {
                    if (Grid.Page != null)
                    {
                        string argument;
                        if (cell.Row.RowType == RowType.Group)
                            argument = string.Format("GroupClick!{0}!{1}!{2}!{3}",
                                                     cell.Row.GroupColumnID, cell.Row[cell.Row.GroupColumnID].DataSourceValue, cell.Row.PrimaryKeyValues,cell.Row.GroupIsExpanded);
                        else argument = string.Format("RecordClick!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues);
                        string link = Grid.EnableCallBack
                                          ? Asynchronous.GetCallbackEventReference(Grid, argument
                                                                                   ,
                                                                                   false, string.Empty, string.Empty)
                                          : Grid.Page.ClientScript.GetPostBackEventReference(Grid, argument);

                        string b = (string.IsNullOrEmpty(ConfirmMessage))
                                       ? string.Empty
                                       : string.Format("if(wgconfirm('{0}',this,'{1}')) ",
                                                       ConfirmMessage.Replace("'", "\\'"),
                                                       Grid.DialogTitle.Replace("'", "\\'"));

                        if (Grid.PopupExtender == null)
                            s = string.Format("<a class=\"wglinkfield\" href=\"#\" onclick=\" {0}{1}\">{2}</a>", b, link,
                                              s);
                        else if (Grid.Scripts == null ||
                                 (!Grid.Scripts.DisableJQuery && !Grid.Scripts.DisablePopupExtender))
                        {
                            string title = string.Empty;
                            if (Grid.PopupExtender.Title != null)
                                title = string.Format(" title=\"{0}\" ",
                                                      HttpUtility.HtmlEncode(Grid.PopupExtender.Title));
                            s =
                                string.Format(
                                    "<a class=\"wgpopupiframe wglinkfield\"{5}href=\"{2}?DetailPopupKeys={1}&amp;TB_Grid=true&amp;TB_iframe=true&amp;height={3}&amp;width={4}\">{0}</a>",
                                    s, cell.Row.PrimaryKeyValues,
                                    Grid.PopupExtender.Url, Grid.PopupExtender.Height, Grid.PopupExtender.Width,
                                    title);

                            Grid.AddClientScript(writer,
                                                 string.Format(
                                                     @"$(document).ready(function() {{$("".wgpopupiframe"").colorbox({{ width: ""{1}px"", height: ""{0}px"", iframe: true }});}});",
                                                     Grid.PopupExtender.Height, Grid.PopupExtender.Width));
                        }

                    }
                }
                StringBuilder indentBuilder = new StringBuilder();
                if (TreeLevel > 0)
                {
                    for (int i = 0; i < TreeLevel; i++)
                        indentBuilder.Append(TreeIndentText);
                    s = indentBuilder + s;
                }
            }
            LabelHtml(s, writer,cell);
        }
Example #51
0
        // 2005.01.09 - jorn, string optimize
        private string CreateRadioButtons(bool tree, string parentValue, int level, RowCell cell)
        {
            bool m_Foreignkeyselected = false;
            StringBuilder s = new StringBuilder(string.Empty);
            for (int i = 0; i < Table.Rows.Count; i++)
            {
                string optionValue = Table.Rows[i].PrimaryKeyValues;

                if (!string.IsNullOrEmpty(IdentityColumn) && Table.Rows[i][IdentityColumn].Value != null)
                    optionValue = Table.Rows[i][IdentityColumn].Value.ToString();

                if (tree)
                {
                    string treeValue = null;

                    if (Table.Rows[i][TreeParentId].Value != null)
                        treeValue = Table.Rows[i][TreeParentId].Value.ToString();
                    if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(optionValue))
                        continue;
                }

                if (i != 0)
                {
                    if (m_Rowcounter == 0)
                    {
                        s.Append("</tr><tr><td>");
                        m_Rowcounter = RecordsPerRow;
                    }
                    else
                        s.Append("<td>");
                }
                m_Rowcounter--;
                string selected = string.Empty;

                if (!m_Foreignkeyselected && optionValue != null)
                {
                    if (cell.PostBackValue != null)
                        selected = Equals(optionValue, cell.PostBackValue)
                                       ? " checked=\"checked\" "
                                       : string.Empty;
                    else if (cell.Value != null)
                        selected = Equals(optionValue, cell.Value.ToString()) ? "checked=\"checked\" " : string.Empty;
                    else if (RememberState && string.IsNullOrEmpty(selected) && (string)Grid.GetState(cell.CellClientId) != null)
                    {
                        selected =
                            (String.Compare(optionValue, Grid.GetState(cell.CellClientId) as string, true) == 0)
                                ? "checked=\"checked\" "
                                : string.Empty;
                    }
                    if (string.IsNullOrEmpty(selected) == false)
                        m_Foreignkeyselected = true;
                }
                StringBuilder optionText = new StringBuilder(string.Empty);
                if (level > 0)
                {
                    for (int j = 0; j < level; j++)
                        optionText.Append(TreeIndentText);
                }
                try
                {
                    optionText.Append(BuildDisplayText(i, ValueColumn, Table));
                }
                catch (Exception e)
                {
                    throw new GridException(string.Format("Error creating radio buttons rows for foreign keys ({0})", ColumnId),
                                            e);
                }
                StringBuilder javascript = new StringBuilder();
                if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false)
                {
                    StringBuilder eventScript = new StringBuilder(" onchange=\"");
                    if (string.IsNullOrEmpty(ConfirmMessage) == false)
                        eventScript.AppendFormat(" if(confirm('{0}')) ", ConfirmMessage);
                    string link = Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid,
                                                                                               string.Format("ElementPostBack!{0}!{1}",
                                                                                                             ColumnId, cell.Row.PrimaryKeyValues), false,
                                                                                               string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                                                                                                              string.Format(
                                                                                                                                                                                  "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues));
                    eventScript.AppendFormat("{0}\"", link);

                    javascript.Append(eventScript);
                }
                s.AppendFormat(
                    "<input type=\"radio\" id=\"rb_{0}_{1}\" {4} name=\"{0}\" value=\"{1}\" {3} /><label class=\"wglabel\" for=\"rb_{0}_{1}\">{2}</label>",
                     cell.CellClientId, optionValue, optionText, selected, javascript);
                if (tree)
                    s.Append(CreateRadioButtons(true, optionValue, level + 1, cell));
            }
            return s.ToString();
        }
Example #52
0
        /*
        internal string RenderGridViewTemplate(RowCell cell)
        {

            if (m_GridViewTemplateCache == null)
            {

                StringBuilder sb = new StringBuilder();
                StringWriter sw = new StringWriter(sb);
                System.Web.UI.HtmlTextWriter controlwriter = new System.Web.UI.HtmlTextWriter(sw);
                m_GridViewTemplate.RenderControl(controlwriter);
                m_GridViewTemplateCache = sb.ToString();
                sw.Close();
                sw.Dispose();
                if (
                       m_GridViewTemplateCache.IndexOf(string.Format("[{0}]", ColumnId),
                                                           StringComparison.OrdinalIgnoreCase) != -1)
                    throw new GridException(string.Format("The template '{0}' can't contain reference to itself.",
                                                          ColumnId));
            }

            if (!m_GridViewTemplateCache.Contains("["))
                return m_GridViewTemplateCache;
            string content = m_GridViewTemplateCache;
            cell.Row.Columns.ForEach(delegate(Column column)
                                    {
                                        if (
                                            content.IndexOf(string.Format("[{0}]", column.ColumnId),
                                                             StringComparison.OrdinalIgnoreCase) == -1)
                                            return;

                                        HtmlTextWriter writer = new HtmlTextWriter(Grid);
                                        Visibility columnvisibility = column.Visibility;
                                        column.Visibility = Visibility;
                                        column.SystemMessageStyle = SystemMessageStyle.WebGrid;
                                        if (Grid.Trace.IsTracing)
                                            Grid.Trace.Trace("Rendering ColumnName: {0} in column: {1}",
                                                              column.ColumnId, ColumnId);
                                         column.RenderEditView(writer, cell.Row.Cells[column.ColumnId]);
                                        column.Visibility = columnvisibility;
                                        if (column.AllowEdit)
                                            writer.Write(
                                                "<input type=\"hidden\" value=\"validate\" name=\"{0}_{1}_validate\" />",
                                                m_Grid.ClientID, column.ColumnId);
                                        content = content.Replace(string.Format("[{0}]", column.ColumnId),
                                                                  writer.ToString());
                                    });
            return content;
        }
        internal string RenderDetailViewTemplate(RowCell cell)
        {
            if (m_DetailViewTemplate == null )
                return null;

            if (m_DetailViewTemplateCache == null)
            {

                StringBuilder sb = new StringBuilder();
                StringWriter sw = new StringWriter(sb);
                System.Web.UI.HtmlTextWriter controlwriter = new System.Web.UI.HtmlTextWriter(sw);
                m_DetailViewTemplate.RenderControl(controlwriter);
                m_DetailViewTemplateCache = sb.ToString();
                sw.Close();
                sw.Dispose();
                if (
                    m_DetailViewTemplateCache.IndexOf(string.Format("[{0}]", ColumnId),
                                                      StringComparison.OrdinalIgnoreCase) != -1)
                    throw new GridException(string.Format("The template '{0}' can't contain reference to itself.",
                                                          ColumnId));
            }

            if (!m_DetailViewTemplateCache.Contains("["))
                return m_DetailViewTemplateCache;
            string content = m_DetailViewTemplateCache;
            cell.Row.Columns.ForEach(delegate(Column column)
                                    {
                                        if (
                                            content.IndexOf(string.Format("[{0}]", column.ColumnId),
                                                            StringComparison.OrdinalIgnoreCase) == -1)
                                            return;
                                        HtmlTextWriter writer = new HtmlTextWriter(Grid);
                                        Visibility columnvisibility = column.Visibility;
                                        column.Visibility = Visibility;
                                        column.SystemMessageStyle = SystemMessageStyle.WebGrid;
                                        if (Grid.Trace.IsTracing)
                                            Grid.Trace.Trace("Rendering ColumnName: {0} in column: {1}",
                                                             column.ColumnId, ColumnId);
                                        column.RenderEditView(writer, cell.Row.Cells[column.ColumnId]);
                                        column.Visibility = columnvisibility;
                                        if (column.AllowEdit)
                                            writer.Write(
                                                "<input type=\"hidden\" value=\"validate\" name=\"{0}_{1}_validate\" />",
                                                m_Grid.ClientID, column.ColumnId);
                                        content = content.Replace(string.Format("[{0}]", column.ColumnId),
                                                                  writer.ToString());
                                    });
            return content;
        }
        */
        internal virtual void GetColumnPostBackData(RowCell cell)
        {
            if (cell.GotPostBackData || !m_Grid.GetColumnsPostBackData)
                 return;

            string uniqueID = cell.CellClientId;
            if (Grid.GotHttpContext && HttpContext.Current.Request.Form[uniqueID] != null)
            {
                cell.PostBackValue = HttpContext.Current.Request.Form[uniqueID];

                cell.GotPostBackData = true;

                if (Grid.Trace.IsTracing)
                    Grid.Trace.Trace("{0} ({2}) contains post back-data '{1}'", uniqueID, cell.PostBackValue, ColumnId);
            }
            else
            {
                if (Grid.Trace.IsTracing)
                    Grid.Trace.Trace("{0} ({2}) was not found for post back-data ({1})", uniqueID, uniqueID, ColumnId);
            }
        }
Example #53
0
        internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell)
        {
            if (!string.IsNullOrEmpty(Sum) && cell.Row.RowType == RowType.DataRow)
                cell.Value = GetSum(cell);

            base.RenderLabelView(writer, cell);
        }
Example #54
0
        /// <summary>
        /// Used to validate data source against on update insert.
        /// </summary>
        /// <param name="ea">insertupdate argument</param>
        /// <param name="cell">Rowcell</param>
        internal virtual void OnUpdateInsert(CellUpdateInsertArgument ea, RowCell cell)
        {
            // Fix value
            ea.AddApostrophe = true;

            if (IsInDataSource == false || (ea.Value != null && ea.Value.Equals(cell.DataSourceValue)) || (( ea.Value == DBNull.Value) && (ea.DataSourceValue == null)) )
                ea.IgnoreChanges = true;
            if (ea.Value == null)
                ea.AddApostrophe = false;
        }
Example #55
0
 internal new virtual decimal? Value(RowCell cell)
 {
     LoadValueFromColumnDataSource(cell);
     if (cell.Value is decimal) return (decimal)cell.Value;
     if (cell.Value == null)
         return null;
     decimal result;
     if (
         decimal.TryParse(cell.Value.ToString(),
                          NumberStyles.Any | NumberStyles.AllowTrailingWhite |
                          NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite |
                          NumberStyles.AllowTrailingWhite, Grid.Culture,
                          out result))
         return (decimal?)(cell.Value = result);
     return null;
 }
Example #56
0
        internal void LabelHtml(string text, HtmlTextWriter writer, RowCell cell)
        {
            if (string.IsNullOrEmpty(PreGridText) == false && m_Grid.DisplayView == DisplayView.Grid)
                writer.Write(PreGridText);
            else if (string.IsNullOrEmpty(PreDetailText) == false && m_Grid.DisplayView == DisplayView.Detail)
                writer.Write(PreDetailText);

            writer.Write(text);

            if (string.IsNullOrEmpty(PostGridText) == false && m_Grid.DisplayView == DisplayView.Grid)
                writer.Write(PostGridText);
            else if (string.IsNullOrEmpty(PostDetailText) == false && m_Grid.DisplayView == DisplayView.Detail)
                writer.Write(PostDetailText);
        }
Example #57
0
        private void DesignRenderDetail(HtmlTextWriter writer,RowCell cell)
        {
            // 16.10.2004, jorn - Kommenterte ut EditAlign....

            if (Grid.BasicDetailLayout)
                RenderEditView(writer,cell);
            else
            {
                StringBuilder tdStart = new StringBuilder("<td ");

                if (cell != null && cell.InternalCellSpan > 0)
                    tdStart.AppendFormat(" colspan=\"{0}\"", cell.InternalCellSpan);
                if (WidthColumnTitle != Unit.Empty)
                    tdStart.AppendFormat(" width=\"{0}\"", WidthColumnTitle);

                // 16.10.2004, jorn - Det er dataene vi skal aligne, ikke selve input boksen.
                // ja?
                if (ColumnType == ColumnType.GridColumn && EditAlign != HorizontalPosition.Undefined)
                    tdStart.AppendFormat(" align=\"{0}\"", EditAlign);

                if (EditVAlign != VerticalPosition.undefined)
                    tdStart.AppendFormat(" valign=\"{0}\"", EditVAlign);

                if (CssClass != null)
                    tdStart.AppendFormat(" class=\"wgdetailcell {0}\">", CssClass);
                else
                    tdStart.Append(" class=\"wgdetailcell\">");
                writer.Write(tdStart);
                RenderEditView(writer,cell);

                writer.Write("</td>");
            }
        }
Example #58
0
        internal virtual void RenderEditView(HtmlTextWriter writer, RowCell cell)
        {
            if (Identity | AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false))
            {
                RenderLabelView(writer, cell);
                return;
            }
            GetColumnPostBackData(cell);

            string uniqueID = cell.CellClientId;

            string theValueToShow = DisplayText(cell);
            theValueToShow = HttpUtility.HtmlEncode(theValueToShow);

            StringBuilder cssstyle = new StringBuilder();
            if (WidthEditableColumn != Unit.Empty)
                cssstyle.AppendFormat("width: {0};", WidthEditableColumn);
            if (HeightEditableColumn != Unit.Empty)
                cssstyle.AppendFormat("height: {0};", HeightEditableColumn);

            if (EditAlign != HorizontalPosition.Undefined)
                cssstyle.AppendFormat("text-align: {0};", EditAlign);

            StringBuilder onblur = new StringBuilder(" onblur=\"");
            string script = string.Empty;
            if (Grid.InputHighLight != Color.Empty)
            {
                script =
                    string.Format(
                        " onfocus=\"this.accessKey = style.backgroundColor;style.backgroundColor='{0}';\"",
                        Grid.ColorToHtml(Grid.InputHighLight));
                onblur.Append("style.backgroundColor=this.accessKey;");
            }
            if (Grid.ColumnChangedColour != Color.Empty)
                onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour));

            if (AutoPostback)
            {
                onblur.Append("if(hasChanged(this))");
                onblur.Append(Grid.EnableCallBack && !ForcePostBack
                                  ? Asynchronous.GetCallbackEventReference(Grid,
                                                                           string.Format("ElementPostBack!{0}!{1}",
                                                                                         ColumnId,
                                                                                         cell.Row.PrimaryKeyValues),
                                                                           false,
                                                                           string.Empty, string.Empty).Replace(
                                        "javascript:", "")
                                  : Grid.Page.ClientScript.GetPostBackEventReference(Grid,
                                                                                     string.Format(
                                                                                         "ElementPostBack!{0}!{1}",
                                                                                         ColumnId,
                                                                                         cell.Row.PrimaryKeyValues)));

            }
            onblur.AppendFormat("\"{0}", script);

            string mask = null;

            if (!DisableMaskedInput && GenerateColumnMask != null)
            {
                string maskId = string.Format("{0}_{1}", Grid.ID, ColumnId);
                if (!Grid.MaskedColumns.ContainsKey(maskId))
                    Grid.MaskedColumns.Add(maskId, GenerateColumnMask);

                mask = string.Format(" alt=\"{0}\"", maskId);
            }
            string s = string.Format(
                "<input type=\"text\" {0} {4}{5} class=\"wgeditfield\" style=\"{1}\" value=\"{2}\" id=\"{3}\" name=\"{3}\"/>",
                onblur, cssstyle, theValueToShow, uniqueID, Attributes, mask);

            if (string.IsNullOrEmpty(m_ToolTipInput) == false)
                s = Tooltip.Add(s, m_ToolTipInput);

            EditHtml(s, writer, cell);
        }
Example #59
0
        ///<summary>
        /// Image Resize
        ///</summary>
        ///<param name="image">The image you want to resize</param>
        ///<param name="path">Path to store the image</param>
        ///<param name="fileName">Filename for the image</param>
        ///<param name="cell">WebGrid RowCell</param>
        ///<returns></returns>
        ///<exception cref="GridException"></exception>
        public string Resize(System.Drawing.Image image, string path, string fileName, RowCell cell)
        {
            if (!string.IsNullOrEmpty(Directory))
                    path = Directory;
                if (!string.IsNullOrEmpty(FileName))
                    fileName = FileName;

                if (Width < 1)
                    throw new ArgumentException("Width is 0 or less");
                if (Height < 1)
                    throw new ArgumentException("Height is 0 or less");
                if (string.IsNullOrEmpty(fileName))
                    throw new ArgumentException("FileName is empty");
                if (string.IsNullOrEmpty(path))
                    throw new ArgumentException("Directory is empty");
                if (image == null)
                    throw new ArgumentException("Image is null");
                if (cell != null && cell.Row != null && fileName.Contains("["))
                {
                    string tmp_file = fileName;
                    cell.Row.Columns.ForEach(delegate(Column column)
                                                 {
                                                     if (
                                                         tmp_file.IndexOf(string.Format("[{0}]", column.ColumnId),
                                                                          StringComparison.OrdinalIgnoreCase) == -1)
                                                         return;
                                                     if (cell.Row[column.ColumnId].Value != null)
                                                         tmp_file =
                                                             tmp_file.Replace(string.Format("[{0}]", column.ColumnId),
                                                                              cell.Row[column.ColumnId].Value.ToString());
                                                     else
                                                         tmp_file =
                                                             tmp_file.Replace(string.Format("[{0}]", column.ColumnId),
                                                                              "");

                                                 });
                    fileName = tmp_file;
                }
                if (!string.IsNullOrEmpty(Path.GetExtension(fileName)))
                    fileName = fileName.Replace(Path.GetExtension(fileName), "");

                string ret;
                System.Drawing.Image bitMapImage = null;

                try
                {
                    if (CustomGraphics != null)
                    {
                         bitMapImage = new Bitmap(image.Width, image.Height, CustomGraphics);
                        CustomGraphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
                    }
                    else
                        bitMapImage = ResizeImage(image, Width, Height, KeepAspectRatio, EnlargeSmallerImages);

                    string file = UseFileName
                                      ? string.Format("{0}{1}{2}{3}.{4}", path, Prefix, fileName, Suffix, ImageFormat)
                                      :
                                          string.Format("{0}{1}{2}.{3}", path, Prefix, Suffix, ImageFormat);
                    if (System.IO.File.Exists(file))
                        System.IO.File.Delete(file);
                    bitMapImage.Save(file, ImageFormat);
                    ret = path + Prefix + fileName + Suffix;
                }
                catch (Exception ee)
                {
                    throw new GridException(
                        string.Format("Error resizing image file: {0}",
                                      string.Format("{0}{1}{2}{3}.{4}", path, Prefix, fileName, Suffix, ImageFormat)),
                        ee);
                }
                finally
                {
                    if (bitMapImage != null)
                        bitMapImage.Dispose();
                  }
                return ret;
        }
Example #60
0
        private void DesignRenderGrid(HtmlTextWriter writer,RowCell cell)
        {
            if (Grid == null)
                return;
            StringBuilder tdStart = new StringBuilder();
            StringBuilder style = new StringBuilder();

            if (CssClass != null)
                tdStart.AppendFormat("<td class=\"wggridcell {0}\" ", CssClass);
            else
                tdStart.Append("<td class=\"wggridcell\"");

            if (cell != null && cell.InternalCellSpan > 0)
                tdStart.AppendFormat(" colspan=\"{0}\"", cell.InternalCellSpan);
            if (Rowspan > 1) tdStart.AppendFormat(" rowspan=\"{0}\"", Rowspan);

            if( cell != null )
                tdStart.AppendFormat(" id=\"{0}{1}r{2}\"", Grid.ID, ColumnId, cell.Row.RowIndex);
            else
                tdStart.AppendFormat(" id=\"{0}{1}\"", Grid.ID, ColumnId);

            if (GridAlign != HorizontalPosition.Undefined)
                style.AppendFormat("text-align :{0};", GridAlign);
            else if (Grid.RecordsPerRow > 1) // GUESSING IT IS A PRODUCTLIST OR SOMETHING SIMILAR..
                style.Append("width: 100%;text-align : center;vertical-align:top");

            if (style.Length > 1)
                tdStart.AppendFormat(" style=\"{0}\"", style);

            if (GridVAlign != VerticalPosition.undefined)
                tdStart.AppendFormat(" valign=\"{0}\"", GridVAlign);

            if (cell != null)
            {
                if (!string.IsNullOrEmpty(writer.Grid.OnClientCellClick))
                {
                    ClientCellEventArgs ea = new ClientCellEventArgs
                                                 {
                                                     ColumnId = ColumnId,
                                                     RowIndex = cell.Row.RowIndex,
                                                     Value = cell.Value,
                                                     ClientEventType = ClientEventType.OnClientColumnClick
                                                 };

                    string content = JavaScriptConvert.SerializeObject(ea);
                    writer.Grid.JsOnData.AppendLine();
                    string jsonId = string.Format("{0}r{2}{1}click", Grid.ID, ColumnId, cell.Row.RowIndex).Replace("-",
                                                                                                                   "A");

                    writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                    tdStart.AppendFormat(@"onclick=""{0}(this,{1});return false""", writer.Grid.OnClientCellClick,
                                         jsonId);
                }
                if (!string.IsNullOrEmpty(writer.Grid.OnClientCellDblClick))
                {
                    ClientCellEventArgs ea = new ClientCellEventArgs
                                                 {
                                                     ColumnId = ColumnId,
                                                     RowIndex = cell.Row.RowIndex,
                                                     Value = cell.Value,
                                                     ClientEventType = ClientEventType.OnClientColumnDblClick
                                                 };

                    string content = JavaScriptConvert.SerializeObject(ea);
                    writer.Grid.JsOnData.AppendLine();
                    string jsonId =
                        string.Format("{0}r{2}{1}dblclick", Grid.ID, ColumnId, cell.Row.RowIndex).Replace("-", "A");

                    writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                    tdStart.AppendFormat(@"ondblclick=""{0}(this,{1});return false""", writer.Grid.OnClientCellDblClick,
                                         jsonId);
                }
                if (!string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOver))
                {
                    ClientCellEventArgs ea = new ClientCellEventArgs
                                                 {
                                                     ColumnId = ColumnId,
                                                     RowIndex = cell.Row.RowIndex,
                                                     Value = cell.Value,
                                                     ClientEventType = ClientEventType.OnClientColumnMouseOver
                                                 };

                    string content = JavaScriptConvert.SerializeObject(ea);
                    writer.Grid.JsOnData.AppendLine();
                    string jsonId =
                        string.Format("{0}r{2}{1}mouseover", Grid.ID, ColumnId, cell.Row.RowIndex).Replace("-", "A");

                    writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                    tdStart.AppendFormat(@"onmouseover=""{0}(this,{1});return false""",
                                         writer.Grid.OnClientCellMouseOver, jsonId);
                }
                if (!string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOut))
                {
                    ClientCellEventArgs ea = new ClientCellEventArgs
                                                 {
                                                     ColumnId = ColumnId,
                                                     RowIndex = cell.Row.RowIndex,
                                                     Value = cell.Value,
                                                     ClientEventType = ClientEventType.OnClientColumnMouseOut
                                                 };

                    string content = JavaScriptConvert.SerializeObject(ea);
                    writer.Grid.JsOnData.AppendLine();
                    string jsonId =
                        string.Format("{0}r{2}{1}mouseout", Grid.ID, ColumnId, cell.Row.RowIndex).Replace("-", "A");

                    writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content);

                    tdStart.AppendFormat(@"onmouseout=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOut,
                                         jsonId);
                }
            }
            tdStart.Append(">");

            writer.Write(tdStart);

            if (NonBreaking)
                writer.Write("<span class=\"wgnowrap\">");

            if (AllowEditInGrid)
            {
                if (Grid != null)
                    if (Grid.MasterTable.Columns.Primarykeys == null ||
                        Grid.MasterTable.Columns.Primarykeys.Count == 0)
                        throw new ApplicationException(
                            string.Format(
                                "Using 'AllowEditInGrid' property requires one or more columns in '{0}' to be a primary key.",
                                Grid.ID));
                RenderEditView(writer, cell);
                if (Identity == false && AllowEdit)
                    if (Grid != null) Grid.m_StoredAllowEditInGrid = true;
            }
            else
                RenderLabelView(writer, cell);
            if (NonBreaking)
                writer.Write("</span>");

            writer.Write("</td>");
        }