Tuesday, August 31, 2010

Grouping/Appending GridView Header

GridView header to have a Parent Header(Grouped Header) is as simple as the following.







protected void
GrvPrePromotion_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridView HeaderGrid = (GridView)sender;
            GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            TableCell HeaderCell = new TableCell();
            HeaderCell.Text = "Promotion Product Group";
            HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);
            HeaderGridRow.CssClass = "gridheadtop";

            HeaderCell = new TableCell();
            HeaderCell.Text = "Sales and SGM";
            HeaderCell.ColumnSpan = 4;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Special Discount";
            HeaderCell.ColumnSpan = 3;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Rebate";
            HeaderCell.ColumnSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Free Goods / Prize";
            HeaderCell.ColumnSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            GrvPrePromotion.Controls[0].Controls.AddAt(0, HeaderGridRow);
        }
    }

 How to Display/Calculate Total/Percentage in the Gridview footer.

Rounding a number to decimal places, Javascript.

As Javascript's Math.Round() cant be directly used to round to decimal places, we should find the workarounds.
Have a look at the following function which does the job.

function RoundNumber(ThisNumber, rlength) { // Arguments: number to round, number of decimal places
  var RoundedNumber = Math.round(ThisNumber*Math.pow(10,rlength))/Math.pow(10,rlength);
  return RoundedNumber ; // returns the resulting number. 
}

Friday, August 27, 2010

WebConfig settings for Sharepoint (WSS and MOSS Portals)

Get Microsoft ASP.NET 2.0 AJAX Extensions 1.0 running on the WFE (WHere the Instance of your WSS/MOSS is running. Open up the Web.config of your WebSite from C:/INETPUB/VIRTUAL DIRECTORIES/WSS/(PORT NUMBER OF YOUR SITE) and do some settings which are required for AJAX to run on your Portal. Web.Config wont have Ajax settings in it even if AJAX is installed on the Server.

FOR WSS

FOR MOSS

ASP.Net Application to run on IIS 7.0

Upgrading an ASP.NET application from IIS 6.0 or lower version to IIS 7.0 will have a lot of work. Microsoft provides an application that does the settings for your application to run on IIS 7.0. [Classic ASP.NET Integration Mode to IIS 7.0 Integrated Mode]

IIS 7.0 takes care of migrating the application by using the APPCMD.EXE command line tool to perform the migration. The migration error message contains the command that is executed in command line window (which you must run--right click the Programs\Accessories\Command Prompt icon, and choose "Run as administrator") in order to instantly migrate your application to Integrated mode.

The format of the migration command is :

%windir%\system32\inetsrv\APPCMD.EXE migrate config

where Application Path is the virtual path of the application containing the site name, such as "Default Web Site/app1"

Monday, August 2, 2010

Use Delegate to Delete an Item from a List

Iterating through the list items is quite a simple task when delegates are in place.

 
protected void GrvUploads_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "DeleNow")
        {
            List oUploader = Session["UploadedFiles"] as List;
            if (oUploader != null)
            {
                oUploader.Remove(oUploader.Find(delegate(UploadEntity oEntity)
                {
                    return (oEntity.UploadID == Convert.ToInt64(e.CommandArgument));
                }
                ));
            }
            Session["UploadedFiles"] = oUploader;
            BindUploadGrid();
        }
    }