How To Remove An Image From The Header Text Of A RadGrid Column



TODO:

Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     try
     {
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.  You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.

How To Add An Image To The Header Text Of a RadGrid Column



TODO:

Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     Image img = new Image();
     Literal space = new Literal();
     space.Text = " ";
     try
     {
          img.ImageUrl = ImageUrl;
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
     finally
     {
          img.Dispose();
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.

How To Add A Custom Filter To A RadEditor That Is An EditItem Of A RadGrid



TODO:

Have you ever wanted to add a custom filter to a RadEditor that is a EditItemTemplate in a RadGrid that lives in a RadAjaxPanel?  To get this accomplished, some out of the ordinary things need to happen, or else you will end up with the dreaded 'Telerik.Web.UI.Editor' is undefined error on page load.

 

SOLUTION:

1. Add JavaScript to the page, that will do some things we want to happen when we go from design to html mode in the RadEditor.

<telerik:RadCodeBlock ID="rcbGirdLoaded" runat="server">
        <script type="text/javascript">
            function StripXSS(content) {
                var newContent = content;
                //Make changes to the content and return it      
                newContent = newContent.replace(/iframe/gi, "");
                newContent = newContent.replace(/javascript:alert/gi, "");
                newContent = newContent.replace(/javascript/gi, "");
                
                //do some other stuff
                return newContent;
            }

            function CreateRadEditorXSSFilter(editor, args) {
                editor.get_filtersManager().add(new MyFilter());
            }

            MyFilter = function () {
                MyFilter.initializeBase(this);
                this.set_isDom(false);
                this.set_enabled(true);
                this.set_name("RadEditor XSS filter");
                this.set_description("RadEditor XSS filter");
            }
            MyFilter.prototype =
            {
                getHtmlContent: function (content) {
                    return StripXSS(content);
                },
                getDesignContent: function (content) {
                    return StripXSS(content);
                }
            }

            //on grid created
            function AddXSSFilter()
            {
                MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);
            }
        </script>
    </telerik:RadCodeBlock>

 

2.  Create your RadEditor, and set OnClientLoad to our function that creates the filter.

<telerik:RadEditor runat="server" ID="txtDescription" OnClientLoad="CreateRadEditorXSSFilter" RegisterWithScriptManager="false"  ToolsWidth="250px" AllowScripts="false" EditModes="Design,Html" >
</telerik:RadEditor>

 

3. Add the client setting to the RadGrid, that will fire when a PopUp is showing (Here we add the filter)

<ClientSettings>
     <ClientEvents OnPopUpShowing="AddXSSFilter" />
</ClientSettings>

 

NOTES:

Basically, MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter); , will cause an error on page load, because 'Telerik.Web.UI.Editor' will be undefined.  We only want to execute that line, once the grid is loaded, and more so when the RadEditor is known.  Since this is in AJAX, and a PopUp editor window, that line needs to happen when the client 'PopUpShowing' event is called.  These code snippets show how to accomlish this.

How To Cancel And Remove Certain Files When Using Telerik RadAsyncUpload



TODO:

Have you ever wanted to remove certain files, when using RadAsyncUpload control in multi select mode?  The problem is, you calling cancelUpload in the Uploading event cancels all uploads.  That is not idea for obvious reasons.

 

SOLUTION:

var errorFiles = '';

//OnClient Uploading Event
function onClientFileUploading(sender, args) {

     //if some condition is met, then cancel the upload, and add the filename to a variable.
     alert('alert user possibly that file will be removed');

     //cancel the upload
     args.set_cancel(true);

     //add to error list, we will need to remove in the Uploaded event...as it still fires.
     errorFiles = errorFiles + currentUploadedFilename.toUpperCase() + '|';
}

//OnClient Uploaded Event
function onClientFileUploaded(sender, args) {
     //create array of file names
     var filename = errorFiles.split("|");
     var count = filename.length;
     
     //process each filename
     $.each(filename.reverse(), function (key, item) {
          if (args.get_fileName().toUpperCase() == item.toUpperCase()) {
               //remove click
               $telerik.$(".ruRemove", args.get_row()).click();
               filename[key] = '';
               return;
          }
     })
     errorFiles = '';
     $.each(filename.reverse(), function (key, item) {
          if (item.length > 0) {
               errorFiles = errorFiles + item.toUpperCase() + '|';
          }
     })
}

 

NOTES:

This snippet of code, will allow you to choose files to cancel during the upload process, and then automatically remove them from the list of documents automatically.

How To Use A CASE Statement In A Select In T-SQL (SQL Server)



TODO:

Have you ever wanted to use a CASE statement in a SELECT statement in T-SQL?

 

SOLUTION:

SELECT  Id,
     CASE PrimaryColor WHEN NULL THEN 
          HeaderColor
     ELSE
          PrimaryColor
     END AS HeaderColor
     ,SectionHeader...
FROM...
WHERE...

 

NOTES:

This example will evaluate the column 'PrimaryColor'.  If it is NULL, then the column 'HeaderColor' will be used.  If it does have a value, then 'PrimaryColor' will be used.

How To Create A Table From a Select Statement Using T-Sql In SQL Server



TODO:

Have you ever wanted to create a table from a SELECT statement in SQL Server?

 

SOLUTION:

SELECT * INTO MyTable_TMP
FROM MyTable

 

NOTES:

There are no notes on this topic.

How To Use A Telerik RadGrad In PopUp Mode For Inserts, And InPlace For Edits



TODO:

Have you ever wanted to use a popup window for inserts to a Telerik RadGrid, but then allow editing to be done InPlace?

 

SOLUTION:

protected void rgdDocuments_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
     if (e.CommandName == RadGrid.EditCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.InPlace;
     }
     if (e.CommandName == RadGrid.InitInsertCommandName)
     {
          rgdDocuments.MasterTableView.EditMode = GridEditMode.PopUp;
     }
}


NOTES:

There are no notes on this topic.

How To Convert A List To A Delimited String



TODO:

Have you ever wanted to take a List<string> and convert it into a delimited string?

 

SOLUTION:

string someString = "test1.txt|test2.txt|test3.txt;
//split the string on | to get a List<string>
List<string> files = someString.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();

//now flatten it to a delimited string
string newValue = string.Join("|", files.Select(x => x).ToArray());

 

NOTES:

There are no notes on this topic

Copy And Paste Or Cut And Paste Stops Working When Running VMWare On Mac



TODO:

You are using VMWare on Mac, to run Windows (any version).  For no apparent reason, copy or cut and paste stops working.

 

SOLUTION:

Suspend the VM, and then go back into it.  Copy or cut and paste should now work.

 

NOTES:

There are no notes on this topic

How To Find Tables With Large Amounts Of Data In SQL Server



TODO:

You want to find tables that contain large amounts of data, which can be due to large row counts.  The solution will get table stats, and sort by row count descending.

 

SOLUTION:

SELECT 
    t.NAME AS 'Table',
    i.name as 'Index',
    sum(p.rows) as 'Rows',
    sum(a.total_pages) as 'Total Pages', 
    sum(a.used_pages) as 'Used Pages', 
    sum(a.data_pages) as 'Data Pages',
    (sum(a.total_pages) * 8) / 1024 as 'Total Space (MB)', 
    (sum(a.used_pages) * 8) / 1024 as 'Used Space (MB)', 
    (sum(a.data_pages) * 8) / 1024 as 'Data Space (MB)'
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE 
    t.NAME NOT LIKE 'dt%' AND
    i.OBJECT_ID > 255 AND   
    i.index_id <= 1
GROUP BY 
    t.NAME, i.object_id, i.index_id, i.name 
ORDER BY 
    Rows DESC

 

NOTES:

There are no notes on this topic.