Aug
17
2010

ASP .NET - How to customize web part title bar / WebPart Chrome

Has there ever been anything so hard - but then again so easy?

You would think that this would be easier -

After much research I have come to the conclusion that there is no easy way to just set a property of a WebPart Title area and set the background to use an image.

It looks like to me that Microsoft left out a Property for the title area background image.

You would think that this would be easier - I can almost bet that Microsoft has had numerous request to add it.

I resulted to using a style sheet class

    <style type="text/css">
        .CoolBar {
         background-image :url(images/sweetBar.gif);
        }
    </style>

  <PartTitleStyle CssClass="CoolBar" BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />

Other Links of Interest on Webparts / Web Parts

http://www.phptr.com/articles/article.asp?p=703789&seqNum=2&rl=1

Aug
17
2010

Making a Client Customizable ASP.net Gridview

Recently I had a request to change the column header in a gridvew report.

Source Code Download is at the bottom of this post

Although the actual column header "Column A" meant the same as "Column a" I did not wish to maintain separate reports for different clients.

So to handle this issue I made it so that the client could update and XML file and change the column names themselves.
First the XML

<code>
<?xml version="1.0" standalone="yes"?>
<REPORT_LAYOUT>
  <COLUMNS>
   
<COLUMN ColumnName="account_num"   HeaderText="Account Number" FontName="Verdana" FontSize="8"  FontBold="true" />
    <COLUMN ColumnName="company_name"  HeaderText="Company Name"   FontName="Times"   FontSize="10" FontBold="true"  />
    <COLUMN ColumnName="account_name"  HeaderText="Account Name"   FontName="arial"   FontSize="12" FontBold="true" />
  </COLUMNS>
</REPORT_LAYOUT>
</code>

There are 5 attributes in the of each column
1) ColumnName this is the column name that is returned by the database in the DataSet or in our case a DataTable.
2) HeaderText this is the actual text that will be used to replace the Header Row in our GridView.
3) FontName - this show be self explanatory
4) FontSize - this show be self explanatory
5) FontBold - this show be self explanatory

Connection to a Database is not required for this article so as you can see In the Page_Load event I build
A DataTable from code and insert some sample data and then bind it to the GridView ( Gridview1 ).


<code>
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable objDataTable = new DataTable();
        objDataTable.Columns.Add("account_num", typeof(string));
        objDataTable.Columns.Add("company_name", typeof(string));
        objDataTable.Columns.Add("account_name", typeof(string));

        DataRow objDataRow = objDataTable.NewRow();

        objDataRow["account_num"] = "00001";
        objDataRow["company_name"] = "Acme Golf";
        objDataRow["account_name"] = "Sues Account";
        objDataTable.Rows.Add(objDataRow);

        objDataRow = objDataTable.NewRow();

        objDataRow["account_num"] = "00003";
        objDataRow["company_name"] = "Cup of Tea";
        objDataRow["account_name"] = "Johns Account";
        objDataTable.Rows.Add(objDataRow);

        objDataRow = objDataTable.NewRow();

        objDataRow["account_num"] = "971234";
        objDataRow["company_name"] = "Breakfast Delights";
        objDataRow["account_name"] = "BOBs Account";
        objDataTable.Rows.Add(objDataRow);

        GridView1.DataSource = objDataTable;
        GridView1.DataBind();
    }
</code>

The real beauty of this technique is occurs in the OnRowCreated event for the GridView as shown below.
In this event we detect when the header row is being created, then we take the cell text (which happens to be the column name form the database) and pass it to a function that we created to retrieve the information from the XML file to format our columns the way the client wishes.

<code>
    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        //We could also have formated each cell with a tablestyle class object as well.
        //TableItemStyle tableStyle = new TableItemStyle();
        //tableStyle.HorizontalAlign = HorizontalAlign.Center;
        //tableStyle.VerticalAlign = VerticalAlign.Middle;
        //tableStyle.Font.Name = "Verdana";
        //tableStyle.Font.Size = 12;

        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                cell.Font.Name = GetColumnDetailsFromXML(cell.Text, "FontName");
                cell.Font.Size = FontUnit.Parse(GetColumnDetailsFromXML(cell.Text, "FontSize"));
                cell.Font.Bold = System.Convert.ToBoolean(GetColumnDetailsFromXML(cell.Text, "FontBold"));
                cell.Text = GetColumnDetailsFromXML(cell.Text, "HeaderText");

                //cell.ApplyStyle(tableStyle); //- We could also have formated each cell with a tablestyle class object as well.
            }
        }
    }
</code>

In the function below we read the XML file CustomizeGridview.xml to retrieve the information for each datarow.
We pass the columnName to the function and use SelectSingleNode and an XPATH query to select the exact row in the XML file that we are looking for.

Example of use for this function is: GetColumnDetailsFromXML("account_num", "FontSize");

<code>
    string GetColumnDetailsFromXML(string columnName, string columnAttribute)
    {
        try
        {
            // Load the XML file.
            string xmlFile = Server.MapPath("CustomizeGridview.xml");
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlFile);

            string myNodeQuery = "REPORT_LAYOUT/COLUMNS/COLUMN[@ColumnName='" + columnName + "']";
            XmlNode node = doc.SelectSingleNode(myNodeQuery);

            foreach (XmlAttribute attrib in node.Attributes)
            {
                if (attrib.Name == columnAttribute)
                {
                    return attrib.Value;
                }
            }

            return "";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
</code>

 The above technique can be adabted to most grids on the market not just the GridView.

CustomGridView.zip (3.01 kb)

Aug
17
2010

Active Reports Dynamic Column Generation for .Net, C#, VB.Net

This article assumes you know a little bit about Data Dynamics Active Reports for .Net, so I am not going to bother going over each step of creating a report from scratch.

This Example is in C# but you can covert it to vb.net very easily.

A Link to the file for download is located at the bottom of this post.

This report generates a PDF FILE based on the Active Reports Samples supplied by Data Dynamics.

In order to create Dynamic columns in an Active Report

Create a New Active Report and open it
[Right Click] in the Page Header and in the popup menu select INSERT GROUP HEADER/FOOTER.

Now that your Group Header area has been created we can get started.

Make a note of the names of the Group Header and Detail section.

Click on each area and view the properties.

For my project my Group Header is called "groupHeader1" and my detail area is simply "detail".

Note: The names above are case sensitive in both C# and VB.net.

Note: You can not add controls in the detal format event of the report is actually a row processing event and fires once per-row of data, and at this point the report expects all controls to have already been added to the report.

Now the thing to note about creating Dynamic Columns in Active Reports is that I usually create them
in the Report_Start event and add both a column header / (label) and a data column (textbox).

When generating column labels and text boxes it is up to you to keep track of the X - Y location on the screen of  each controls.

We accomplish this by creating a variable called xPosition and fieldWidth to use to track where on the row we are as shown in the example:

xPosition is the calculated X position on the screen where the label and texbox will be created
fieldWidth is used to add to the xPosition on the screen for adding a new column to the right of the current column

float xPosition = 0F;     // Used to save the X position as the fileds and columns are created across the report
            float fieldWidth = 1.0F;  // The default width of the field to be displayed
            xPosition += fieldWidth + 0.2F; // calculate the position of the next field also
                                            // add a little padding to seperate the columns from each other on the report

When creating each label and text box you want to make sure that you add each control to the correct section of the report

Adding labels to the Group Header:

Before we can add a control to the controls collection we need to issue a new to the control.
Otherwise while we are processing in our loop the new control name will be the same.
So here we use the iLoop counter to append to the label name ( we do the same thing with the text box below)
dyHeaderLabel.Name = "dyHeaderLabel" + iLoop;

Now we set the label text to be equal to the name of the column in our dataset table.
dyHeaderLabel.Text = oDataColumn.ColumnName.ToString().Trim().ToUpper();

Here we add the control to the groupHeader1 section of our report.
this.Sections["groupHeader1"].Controls.Add(dyHeaderLabel);

Adding the text boxes to the Detail area:

Assign the datafield of the text box for the data binding of the Detail Format event
dyTextBox.DataField = oDataColumn.ColumnName.ToString();

Give the control a unique name by appending iLoop counter to the name
dyTextBox.Name = "dyTextBox" + iLoop;

Add the control to the details control collection
this.detail.Controls.Add(dyTextBox);

Report_Start

    private void MyReport_ReportStart(object sender, EventArgs e)
    {
        string sError = "";
        try
        {
            float xPosition = 0F;      // Used to save the X position as the fields and columns are created across the report
            float fieldWidth = 1.0F;  // The default width of the field to be displayed

            DataSet oDataSet;
            oDataSet = (DataSet)this.DataSource;

            Int16 iLoop = 0;

            foreach (DataColumn oDataColumn in oDataSet.Tables[0].Columns)
            {

                iLoop++;

                //----------------------------------------------------------------------------------------------
                //- ADD THE LABELS TO THE GROUP HEADER AREA OF THE REPORT
                //----------------------------------------------------------------------------------------------

                Label dyHeaderLabel = new Label();

                dyHeaderLabel.Name = "dyHeaderLabel" + iLoop;
                dyHeaderLabel.Text = oDataColumn.ColumnName.ToString().Trim().ToUpper();
                dyHeaderLabel.Visible = true;
                dyHeaderLabel.Width = fieldWidth;
                dyHeaderLabel.Font = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Bold);  //BOLD THE HEADER LABELS
                dyHeaderLabel.Location = new System.Drawing.PointF(xPosition, 0.0F);

                this.Sections["groupHeader1"].Controls.Add(dyHeaderLabel);

                //----------------------------------------------------------------------------
                //- ADD THE TEXT BOX FIELDS TO THE DETAILS AREA OF THE REPORT
                //----------------------------------------------------------------------------
                TextBox dyTextBox = new TextBox();
                dyTextBox.Name = "dyTextBox" + iLoop;
                dyTextBox.DataField = oDataColumn.ColumnName.ToString();
                dyTextBox.Visible = true;
                dyTextBox.Width = fieldWidth;
                dyTextBox.Font = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Regular);
                dyTextBox.Location = new System.Drawing.PointF(xPosition, 0.0F);

                this.detail.Controls.Add(dyTextBox);

                xPosition += fieldWidth + 0.2F; // add a little padding to seperate the columns from each other on the report

            }

        }
        catch (Exception ex)
        {
            sError = ex.Message;
        }
        finally
        {

        }
    }

 

DYARColumns.zip (144.27 kb)

Aug
17
2010

RDP RWW Remote Desktop Remote Web Workplace SP3

There seems to be some confusion around the web about the Microsoft Service Pack 3 and RWW and RDP update.

Lots or people are thinking that Microsoft did something to break the RDP / RWW ( web components ) for Remote Desktop Web Component.

The fact is that Microsoft didn't really break the objects they just replaced them with a New Component and New Object Model.

This is an example of the classic / XP SP2 and below.

function ConnectRDPClassic(sServerName,sDomain,sUserId,sPassword,sStartProgram )
{

   var resWidth = screen.width;
   var resHeight = screen.height;

   MsRdpClient = document.getElementById("MsRdpClient");
   MsRdpClient.FullScreen = true;
   MsRdpClient.DesktopWidth = resWidth;
   MsRdpClient.DesktopHeight = resHeight;
   MsRdpClient.Width = resWidth;
   MsRdpClient.Height = resHeight;
     
   MsRdpClient.server = sServerName;
   MsRdpClient.Domain = sDomain;
   MsRdpClient.UserName = sUserId;
   MsRdpClient.AdvancedSettings.ClearTextPassword=sPassword;
  
   if (sStartProgram=='')
           sStartProgram = '\"C:\\Windows\\system32\\notepad.exe\" \';

   MsRdpClient.SecuredSettings.StartProgram = sStartProgram;
   MsRdpClient.Connect();
}

Below is an example of executing the latest version of the RDP / RWW client.

 

This is how you would use the new version of RDP / RWW.

Note that I am using unescape on the sRDPFIle test like this unescape(sRDPFile);

I actually passed the RDP file contents to this function the data is url encoded why does it have to be this way im not totally sure but it works like a champ. If you need an example let me know.

Also note

function ConnectRDP61(sServerName,sDomain,sUser,sPassword,sRDPFile)
{

   var resWidth = screen.width;
   var resHeight = screen.height;

   //Get Pointer to Object to Execute
   MsRdpClient = document.getElementById("MsRdpClient");
   MsRdpClient.FullScreen = true;
   MsRdpClient.DesktopWidth = resWidth;
   MsRdpClient.DesktopHeight = resHeight;
   MsRdpClient.Width = resWidth;
   MsRdpClient.Height = resHeight;
  
   //Device redirection options
   MsRdpClient.AdvancedSettings2.RedirectDrives     = false;
   MsRdpClient.AdvancedSettings2.RedirectPrinters   = true;
   MsRdpClient.AdvancedSettings2.RedirectPorts      = false;
   MsRdpClient.AdvancedSettings2.RedirectSmartCards = false;
  
   //Set Settings and passed RDP File Content
   MsRdpClient.MsRdpClientShell.PublicMode = false;  
   MsRdpClient.MsRdpClientShell.RdpFileContents = unescape(sRDPFile);
   MsRdpClient.authenticationlevel = 2;
   MsRdpClient.negotiatesecuritylayer = 1;
   MsRdpClient.promptforcredentials = 0;

   //Set User Credentials
   MsRdpClient.TransportSettings2.GatewayDomain = sDomain;
   MsRdpClient.TransportSettings2.GatewayUsername = sUser;
   //MsRdpClient.TransportSettings2.GatewayPassword = sPassword;


   //Execute the RDP Object
   MsRdpClient.MsRdpClientShell.Launch()

}

Aug
17
2010

Enable RDP RWW on XP SP3 mstscax.dll msrdp.ocx

After upgrading to Windows XP SP3 / Service Pack 3 you will need to enable the

Microsoft RDP Client Control or the Microsoft Windows Terminal Service

Start Microsoft Internet Explorer

  • Click on Tools -> Internet Options -> Manage add-ons
  • Or click on Click on Tools -> Internet Options -> Programs tab - Select Manage add-ons
  • Highlight Microsoft Terminal Service ActiveX control, which is most likely set to disabled. 
  • Select Enabled  then click OK
  • Close all open versions of Internet Explorer.
  • Restart Internet Explorer.

If your Code is still not working, please see the article below

RDP RWW Remote Desktop Remote Web Workplace SP3

 

Calendar

<<  December 2017  >>
MonTueWedThuFriSatSun
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Category list

None

Page List

Month List

AuthorList