Tuesday, June 29, 2004

Meta Reunion

It was sunday the 27th of June 2004 late evening and i thought of cleaning my office filing cabinet, when i found a sheet of white paper which was no more white ;). This sheet has brought some significant change in life and made me feel more stronger and confident. This sheet had the names, phone nos and email'ds of all my team from good old days of Meta Infotech . I sent a mail to all of them in the hope that these id's still work as its been almost 2 years now and to my surprise most of the id's did work and i got warm replies too :).

I would love to do this with my associations with other organizations too viz.: Genesys & Mediline, oneway it helps get a feedback of oneself on how you treated your team and vice-versa.

Well there is a community created on Orkut called Meta Alumni. If you have not received my invitation, do ping me.

Tuesday, June 22, 2004

Break through firewall

Bypass firewalls to chat with your friends and download files. Works with Kazaa, iMesh, Messenger, ICQ and any other application that supports the SOCKS protocol.

No configuration hassles, no techie-talk or geek-speak. Not only does hopster configure itself, it even knows how to configure Kazaa, MSN Messenger and many others - so you don't need to.
Once installed, hopster operates silently in the background, you won't even notice it's there.

Hopster was designed with the most popular applications in mind: MSN Messenger, ICQ, Yahoo Messenger, Trillian... no matter where your friends are, hopster gets you there. And so are they adding more apps every day.

Hopster also protects you from the nosy Bad Guys on the 'net.

It hides your actual ip address, making it impossible for hackers to trace you. And their firewalls protect you from unwanted visitors.

Download Now

On downloading the demo version, if you get annonyed with the ad bar right click on the title bar and click minimize, this will hide the ad bar for ever and you don't need to buy it unless you need more than 4kb/sec data.

Wednesday, June 09, 2004

Visio to anything

Problem statement:

Couple of weeks back i got myself actively involved with the design team and realized that most of the time was spent in getting the class diagrams from Visio (modelling tool) and stored procedures documented as per the custom design document template.

Technologies
  • Visio,
  • .NET Office Extensibility Add-in,
  • MS Word,
  • VBA,
  • XMI,
  • XSL,
  • CSS

Approach:

Visio does provide a reporting add-in but unfortunately it is neither readable nor is it customizable and so started the thought to work on an alternative.

Microsoft always has a means to automate/customize/extend their products and so do they have UML to XMI Export Functionality, meaning a Visio UML Model can be exported to XML Metadata Interchange (XMI) format. This is build using .NET Office extensibility Add-in.

Now the XMI that is generated by Visio uses UML.dtd, which unfortunately is not distributed by Microsoft but have provided the resource in the readme.txt. With XMI & DTD in place i am sure of a valid Visio XMI file.

The next step was to display the XMI data in a custom format and the best alternative was to use eXtensible Stylesheet Language (XSL), now I needed to understand the structure of Visio XMI file and this is a tough job because there is no documentation available whatsoever to understand how visio model is interpretted in XMI format.

Attached a CSS to XSL to apply the formatting styles including header styles.

The next step was to place this information at an appropriate postion with in the design document template, hence created a .dot file, which is a template file for word.

Created a macro in word VBA that will use MSXML 2.0/4.0 and dynamically translate XMI with XSL and insert it into appropriate position.

Rebuild the table of contents, which will now include the design headings as defined by the CSS.

Please do drop me a comment if you need the UML to XMI add-in/DTD/XSL/CSS/DOT.

Custom Datagrid

This datagrid custom webcontrol will provide out of the box functionalities for the following features:

  • CAT Stylesheet for HeadingItemStyle, EditItemStyle, SelectedItemStyle
  • Inline of Page Redirect on Edit
  • Captions for Edit, Update, Cancel & Delete buttons can be either text or graphic
  • On double click of any row, editcommand, pageredirect of the row will be performed
  • On single click of any row, selectcommand will be performed on the client end, thus saving the roundtrip to server.
  • Sorting of the columns ASC/DESC on corresponding clicks on the column header with glmph
  • Paging of the datagrid
  • Maintaining State Across Pages For Checked Records
  • Complement Inline Edit & Delete Support
  • Fully Editable Support
  • Maintains Concurrency Checks For InlineEdit Records
  • Makes A Particular Row or Column ReadOnly




Code Copy HideScrollFull

///
<summary>
/// File Name: EMSDataGrid.cs
/// Description:
///
<Author> Amith Ellur & Yasin Mukadam</Author>
///
<Date> 11-Feb-2004</Date>
///
<Description>This datagrid custom webcontrol will provide out of the box functionalities for the following:
///1.   CAT Stylesheet for HeadingItemStyle, EditItemStyle, SelectedItemStyle
///2.   Inline of Page Redirect on Edita
///3.   Captions for Edit, Update, Cancel & Delete buttons can be either text or graphic
///4.   On double click of any row, editcommand, pageredirect of the row will be performed
///5.   On single click of any row, selectcommand will be performed on the client end,
///thus saving the roundtrip to server.
///6.  Sorting of the columns ASC/DESC on corresponding clicks on the column header
///7.  Paging of the datagrid
///8.  Maintaining State Across Pages For Checked Records
///9.  Complement Inline Edit & Delete Support
///10. Fully Editable Support
///11. Maintains Concurrency Checks For InlineEdit Records
///12. Makes A Particular Row or Column ReadOnly
///
</Description>
///
</summary>

using
System;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Collections;
using
System.Text;
using
System.IO;
using
Caterpillar.Ems;
using
System.Text.RegularExpressions;
using
System.Web.Handlers;
using
System.Globalization;
using
System.Web;

namespace
Caterpillar.Ems.Controls
{
/// <summary>
/// Summary description for EMSDataGrid.

///
</summary>
[DefaultProperty("Text"),
ToolboxData
("<{0}:EMSDataGrid runat=server></{0}:EMSDataGrid>")]
public
class EMSDataGrid : System.Web.UI.WebControls.DataGrid
{
#region Constant
///
<summary>
///  Used To Set The Default Validator Control Style Sheet

///
</summary>
const
string VALIDATORSTYLESHEET = "RequiredFieldValidator"
///
<summary>
/// Used To Set The Default Range Validator Control Error Message

///
</summary>
const
string RANGEERRORMESSAGE = "<BR><BLINK>||Invalid Data||</BLINK>"
///
<summary>
/// Used To Set The Default Required Validator Control Error Message

///
</summary>
const
string REQUIREDERRORMESSAGE = "<BR><BLINK>||Required||</BLINK>"
///
<summary>
/// Used To Set The Default Regular Validator Control Error Message

///
</summary>
const
string REGULARERRORMESSAGE = "<BR><BLINK>||Invalid Format||</BLINK>"
///
<summary>
/// Used To Set The Default Custom Validator Control Error Message

///
</summary>
const
string CUSTOMERRORMESSAGE = "<BR><BLINK>||Custom Validation Failed||</BLINK>"
///
<summary>
///  Used To Set The Default DropDown Text

///
</summary>
const
string DROPDOWNDEFAULTTEXT = "||-SELECT-||"
///
<summary>
/// Used To Set The DropDownStyle Attribute

///
</summary>
const
string DROPDOWNSTYLE = "DropDownStyle"
///
<summary>
/// Name Of The Hidden CheckboxState Control

///
</summary>
const
string HIDDENCHECKSTATE = "hiddencheckstate"
///
<summary>
/// Name Of The Hidden Control For Storing The NoOfRecordsChecked

///
</summary>
const
string HIDDENNORECORDSCHECKBOXSTATE = "hiddennoofrecordscheckboxstate"
///
<summary>
/// Name Of The Hidden Control For Storing The Total Number Of Records

///
</summary>
const
string HIDDENCHECKBOXSTATECOUNT = "hiddencheckboxstatecount"
///
<summary>
/// Name Of The hidden Control To Store CheckBox State

///
</summary>
const
string HIDDENCONCURRENCYSTATE = "hiddenconcurrencystate"
///
<summary>
/// Name Of The HiddenControlWhich Stores The PreviousPage

///
</summary>
const
string HIDDENPREVIOUSPAGE = "hiddenpreviouspage"
///
<summary>
/// Name Of The ReadOnly TextBoxStyle

///
</summary>
const
string READONLYTEXTBOXSTYLE = "ReadOnlyTextBoxStyle"
///
<summary>
/// Name Of The TextBoxStyle

///
</summary>
const
string TEXTBOXSTYLE = "TextBoxStyle"
///
<summary>
/// Name Of The hidden Control Used For Validating The Selected Record Id

///
</summary>
const
string HIDDENCONCURRENCYIDCONCTROL = "hiddenconcurrencyidcontrol"
#endregion
#region
Member Variables
///
<summary>
/// Defined enumerations for the different types of edit, delete, caption and stylesheet use

///
</summary>
public
enum EditType { UnAuthorized = 0, InLine = 1, PageRedirect = 2 };
///
<summary>
/// Defined enumeration for the different type of delete message

///
</summary>
public
enum DeleteType { DeleteWithConfirmation = 0, DeleteWithOutConfirmation = 1 };
///
<summary>
/// Defined enumeration for the different type of caption Type

///
</summary>
public
enum CaptionType { Text = 0, Graphics = 1 };
///
<summary>
/// Used To Specify The Default Style Sheet

///
</summary>
public
enum StyleSheetType { None = 0, CAT = 1, Default = 2 };
///
<summary>
/// Used To Specify The Status Of The Edit Button

///
</summary>
private
bool editVisible;
///
<summary>
/// Used To Specify The Status Of The Delete Button

///
</summary>
private
DeleteType allowDelete;
///
<summary>
/// Used To Specify The Status Of The Delete Button

///
</summary>
private
bool deleteVisible;
///
<summary>
/// Used To Specify The Control Caption

///
</summary>
private
CaptionType controlCaption;
///
<summary>
/// Used To Specifiy The Style Sheet Type

///
</summary>
private
StyleSheetType styleSheet;
///
<summary>
/// Used To Specify The Status Of Edit On Double Click

///
</summary>
private
bool editOnDoubleClick;
///
<summary>
/// Used To Specify The Status Of The Edit On single Click

///
</summary>
private
bool selectOnSingleClick;
///
<summary>
/// Used To Specify The Id Of The Currently Selected Record On The Client Side

///
</summary>
private
string keyHiddenControlId;
///
<summary>
/// Used To Specify The Status Of Fully Editable Grid

///
</summary>
private
bool blnFullEdidtable;
///
<summary>
/// Used To Specify The Status Of The Inline Edit Enhance Features

///
</summary>
private
bool blnEnhanceEdit;
///
<summary>
/// Stores The DataMembers Extended Properties For Each DataColumn

///
</summary>
private
System.Data.PropertyCollection PropertyCollection;
///
<summary>
/// Stores The Max Decimal Value

///
</summary>
private
string DecimalMaxValue = System.Configuration.ConfigurationSettings.AppSettings["DecimalMaxValue"];
///
<summary>
/// Stores The Min Decimal Value

///
</summary>
private
string DecimalMinValue = System.Configuration.ConfigurationSettings.AppSettings["DecimalMinValue"];
///
<summary>
/// DataTable Which Contains The Modified Data Of The DataGrid After An Post Back From Inline Edit Or Fully Editable grid

///
</summary>
private
DataTable dtModifiedDataTable = new DataTable();
///
<summary>
/// Maintains The Status Of The CheckBox State

///
</summary>
private
bool blnCheckBoxState;
///
<summary>
/// Column Number From The DataMember On Which To Maintain The CheckBox State

///
</summary>
private
int intCheckBoxColumn;
///
<summary>
/// Hidden Control Name Of The CheckBoxState Property

///
</summary>
private
string strHiddenCheckBoxState;
///
<summary>
/// Hidden Control Name Of The CheckBoxState Property

///
</summary>
private
string strNoOfRecordsCheckBoxState;
///
<summary>
/// Hidden Control Name Of The CheckBoxState Property

///
</summary>
private
string strCheckBoxStateCount;
///
<summary>
/// Hidden Control Name Of The Previously Selected Page

///
</summary>
private
string strHiddenPreviousPage;
///
<summary>
/// Number Of Records Selected For The Current Page

///
</summary>
private
int intNoOfRecordsCheckBoxState = 0;
///
<summary>
/// DataSet Which Contains The CheckBox Ids For All The Pages

///
</summary>
private
DataSet dsCheckBoxState;
///
<summary>
/// Stores The Name Of The Hidden Control Of Header Column

///
</summary>
private
string strHeaderCheckBoxId = string.Empty;
///
<summary>
/// Hidden Control Which Stores The Id Of The Currently Selected Row On The Client Side

///
</summary>
private
HtmlInputHidden hidConcurrencyIdControl = new HtmlInputHidden();
///
<summary>
/// Hidden Control Which Stores The Id Of The Currently Selected Row On The Client Side

///
</summary>
private
string strConcurrencyIdControl;
///
<summary>
///

///
</summary>
private
bool blnClearGridStatus = false;
#endregion
#region
Events
///
<summary>
/// define the events for EMS DataGrid. This will be listed under EMS Events

///
</summary>
[Category("EMS Events"), Description("Fires when edit is clicked.")]
public
event DataGridCommandEventHandler EditPage;
///
<summary>
///

///
</summary>
public
event EMSExceptionEventHandler EMSDataGridRaiseException;
#endregion
#region
Properties
///
<summary>
/// Attribute of the control to contain AllowEdit.

/// This will say if we need to provide edit functionality

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if edit option is to be made available.")]
public
EditType AllowEdit
{
get
{
if (!object.Equals(ViewState["allowEdit"], null))
{
return (EditType)ViewState["allowEdit"];
}
else

{
return EditType.InLine;
}
}
set

{
if (!object.Equals(value, null))
{
ViewState["allowEdit"] = value;
}
}
}
///
<summary>
/// Attribute of the control to contain KeyHiddenControlId.

/// This will contain the id of the field to which the datagrid is associated for different functions

/// This will be the id of the associated control

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify the field in which the primary key value has to be displayed.")]
public
string KeyHiddenControlId
{
get
{
return keyHiddenControlId;
}
set

{
keyHiddenControlId = value;
}
}
///
<summary>
/// Attribute of the control to contain AllowDelete.

/// This will say if we need to provide delete functionality

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if delete option is to be made available.")]
public
DeleteType AllowDelete
{
get
{
return allowDelete;
}
set

{
allowDelete = value;
}
}
///
<summary>
/// Attribute of the control to contain controlCaption.

/// This will say what kind of caption is used

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify the caption style for the edit and delete columns.")]
public
CaptionType ControlCaption
{
get
{
return controlCaption;
}
set

{
controlCaption = value;
}
}
///
<summary>
/// Attribute of the control to contain StyleSheet.

/// This will say what kind of StyleSheet is used

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify the style sheet to be used to render the rows.")]
public
StyleSheetType StyleSheet
{
get
{
return styleSheet;
}
set

{
styleSheet = value;
}
}
///
<summary>
/// Attribute of the control to contain EditOnDoubleClick.

/// This will say if we need to provide edit functionality on row double click as well

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if edit to be made available on double clicking the row.")]
public
bool EditOnDoubleClick
{
get
{
return editOnDoubleClick;
}
set

{
editOnDoubleClick = value;
}
}
///
<summary>
/// Attribute of the control to contain SelectOnSingleClick.

/// This will say if we need to provide select functionality on row single click as well

///
</summary>
[Category("EMS Properties"),
DefaultValue
(""), Description("Specify if the row has to be selected on single click.")]
public
bool SelectOnSingleClick
{
get
{
return selectOnSingleClick;
}
set

{
selectOnSingleClick = value;
}
}
///
<summary>
/// Attribute of the control to contain EditVisible.

/// This will say if edit link on the grid will be displayed or not

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if the edit column is to be displayed.")]
public
bool EditVisible
{
get
{
return editVisible;
}
set

{
editVisible = value;
}
}
///
<summary>
/// Attribute of the control to contain EditVisible.

/// This will say if delete link on the grid will be displayed or not

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if the delete column is to be displayed.")]
public
bool DeleteVisible
{
get
{
return deleteVisible;
}
set

{
deleteVisible = value;
}
}
///
<summary>
/// Specify if the Grid Will Be Fully Editable

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if the Grid Will Be Fully Editable.")]
public
bool FullEditable
{
get
{
return this.blnFullEdidtable;
}
set

{
this.blnFullEdidtable = value;
}
}
///
<summary>
/// Specify if the Grid Will Be Contain Enhance Features For Enline Edit.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specify if the Grid Will Be Contain Enhance Features For Enline Edit.")]
public
bool EnhanceEdit
{
get
{
return this.blnEnhanceEdit;
}
set

{
this.blnEnhanceEdit = value;
}
}
///
<summary>
/// Returns The Updated DataSet Of The Grid i.e. When The Update Event Is Fired.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Returns The Updated DataSet Of The Grid i.e. When The Update Event Is Fired.")]
public
DataSet ModifiedDataSet
{
get
{
if (object.Equals(this.DataSource, null) || object.Equals(((DataView)this.DataSource).Table, null))
{
throw new ArgumentNullException("ModifiedDataTable", "This Property Should Be Used To Access The Updated Values From The DataSource");
}

this
.dtModifiedDataTable.TableName = ((DataView)this.DataSource).Table.TableName;

//((DataView)this.DataSource).DataSetName

DataSet
ds = new DataSet();

ds.Tables.Add(this.dtModifiedDataTable);

this
.EditItemIndex = -1;

return
ds;
}
}
///
<summary>
/// Speficies If The CheckBox State Is Going To Be Maintained Accross Pages.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Speficies If The CheckBox State Is Going To Be Maintained Accross Pages.")]
public
bool CheckBoxState
{
get
{
return blnCheckBoxState;
}
set

{
blnCheckBoxState = value;
}
}
///
<summary>
/// Column Number Of The DataSource Of Which To Maintain State.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Column Number Of The DataSource Of Which To Maintain State.")]
public
int CheckBoxColumn
{
get
{
return this.intCheckBoxColumn;
}
set

{
this.intCheckBoxColumn = value;
}
}
///
<summary>
/// Returns The DataSet For Checked Columns Accross Pages.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Returns The DataSet For Checked Columns Accross Pages.")]
public
DataSet ReadCheckBoxStateData
{
get
{
//Validating If The CheckBoxState Member Variable Is Set
if
(this.blnCheckBoxState)
{
//Reading Data From The Hidden Control Into The DataSet
this
.WriteHiddenControl();
//Validating If The DataSet Exists

if
(!object.Equals(this.dsCheckBoxState, null))
{
//Validating If The DataSet Has Any Tables
if
(!object.Equals(this.dsCheckBoxState.Tables[this.DataMember.ToString()], null))
{
//Validating If The Fetched Table Has Any Rows
if
(this.dsCheckBoxState.Tables[this.DataMember.ToString()].Rows.Count == 0)
{
this.ProcessException(new Exception("||No Records Exists In The State Bag||"));
return
null;
}
else

{
//calling the helper function to remove data from the viewstate
//this.ClearCheckBoxState();

//Returning The Newly Populated DataSet

return
this.dsCheckBoxState;
}
}
else

{
this.ProcessException(new ArgumentNullException(this.DataMember.ToString(), "||ReadCheckBoxStateData Method Fetched A DataSet With No Tables||"));
return
null;
}
}
else

{
this.ProcessException(new ArgumentNullException(this.dsCheckBoxState.ToString(), "||ReadCheckBoxStateData Method Fetched An Empty DataSet||"));
return
null;
}
}
else

{
this.ProcessException(new Exception("||Not Authorized To Access This Property If CheckBoxState Property Is Not Set To True||"));
return
null;
}
}
}
///
<summary>
/// Returns The Hidden Control Id Which Contain The No Of Records Checked For Current Page.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Returns The Hidden Control Id Which Contain The No Of Records Checked For Current Page.")]
public
string NoOfRecordsCheckBoxState
{
get
{
return this.strNoOfRecordsCheckBoxState;
}
}
///
<summary>
/// Returns The Hidden Control Id Which Contain The No Of Records Checked For All The Pages.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Returns The Hidden Control Id Which Contain The No Of Records Checked For All The Pages.")]
public
string CheckBoxStateCount
{
get
{
return this.strCheckBoxStateCount;
}
}
///
<summary>
/// Returns The Hidden Control Id Which Contain The checkBox State.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Returns The Hidden Control Id Which Contain The checkBox State.")]
public
string HiddenCheckBoxState
{
get
{
return this.strHiddenCheckBoxState;
}
}
///
<summary>
/// Specifies To Clear The DataSet From The ViewState.

///
</summary>
[Category("EMS Properties"), DefaultValue(""), Description("Specifies To Clear The DataSet From The ViewState.")]
public
void ClearCheckBoxState()
{
//
if
(!object.Equals(this.ViewState[this.strHiddenCheckBoxState], null))
{
this.ViewState.Remove(this.strHiddenCheckBoxState);
}
//

this
.blnClearGridStatus = true;
}
#endregion
#region
OverReidden Events And Method Of The DataGrid
#region
Events That Get Fired Each Time The DataGrid Is Processed
///
<summary>
/// calling the EMS Datagrid Constructor

///
</summary>
public
EMSDataGrid()
{
//Default properties for the datagrid
this
.ShowHeader = true;
this
.AutoGenerateColumns = false;
//this.AllowSorting = true;

this
.BorderColor = Color.Black;
this
.BorderStyle = BorderStyle.Solid;
// Set the Handlers for the events to be handled in EMS Datagrid

CancelCommand += new DataGridCommandEventHandler(EMSDataGrid_CancelCommand);
EditCommand += new DataGridCommandEventHandler(EMSDataGrid_EditCommand);
UpdateCommand += new DataGridCommandEventHandler(EMSDataGrid_UpdateCommand);
SortCommand += new DataGridSortCommandEventHandler(EMSDataGrid_SortCommand);
DataBinding += new EventHandler(EMSDataGrid_DataBinding);
PageIndexChanged += new DataGridPageChangedEventHandler(EMSDataGrid_PageIndexChanged);
}

///
<summary>
/// Get Fired When The Instance If The Grid Is Fired

///
</summary>
///
<param name="e"></param>
protected
override void OnInit(EventArgs e)
{
base.OnInit(e);
this
.Columns.Clear();
if
(this.AllowPaging || this.AllowCustomPaging)
{
this.PagerStyle.Position = PagerPosition.TopAndBottom;
this
.PagerStyle.Mode = PagerMode.NumericPages;
this
.PagerStyle.HorizontalAlign = HorizontalAlign.Left;
this
.PageSize = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["RowsPerPage"].ToString());
}

if
(object.Equals(this.NamingContainer.ClientID, null))
{
this.strConcurrencyIdControl = this.ClientID + ":" + HIDDENCONCURRENCYIDCONCTROL;
}
else

{
this.strConcurrencyIdControl = this.NamingContainer.ClientID + ":" + this.ID + ":" + HIDDENCONCURRENCYIDCONCTROL;
}

//Validating If The CheckBoxState Has To Be Maintained

if
(this.blnCheckBoxState)
{
//Setting CheckBoxStateName
if
(object.Equals(this.NamingContainer.ClientID, null))
{
this.strHiddenCheckBoxState = this.ClientID + ":" + HIDDENCHECKSTATE;
this
.strNoOfRecordsCheckBoxState = this.ClientID + ":" + HIDDENNORECORDSCHECKBOXSTATE;
this
.strCheckBoxStateCount = this.ClientID + ":" + HIDDENCHECKBOXSTATECOUNT;
this
.strHiddenPreviousPage = this.ClientID + ":" + HIDDENPREVIOUSPAGE;
}
else

{
this.strHiddenCheckBoxState = this.NamingContainer.ClientID + ":" + this.ID + ":" + HIDDENCHECKSTATE;
this
.strNoOfRecordsCheckBoxState = this.NamingContainer.ClientID + ":" + this.ID + ":" + HIDDENNORECORDSCHECKBOXSTATE;
this
.strCheckBoxStateCount = this.NamingContainer.ClientID + ":" + this.ID + ":" + HIDDENCHECKBOXSTATECOUNT;
this
.strHiddenPreviousPage = this.NamingContainer.ClientID + ":" + this.ID + ":" + HIDDENPREVIOUSPAGE;
}
}
//

//if(!object.Equals(HttpContext.Current.Session["DataSource"], null) && !object.Equals(HttpContext.Current.Session["DataMember"], null))

//{

//this.DataSource = HttpContext.Current.Session["DataSource"];

//this.DataMember = HttpContext.Current.Session["DataMember"].ToString();

//this.DataBind();

//}
}
///
<summary>
/// Method to handle the DataBinding event of the EMS Datagrid

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void EMSDataGrid_DataBinding(object sender, EventArgs e)
{
//
this
.Columns.Clear();
//                                    

if
(!this.IsTrackingViewState)
{
this.TrackViewState();
}
//if the page is loading for the first time, set the sort order to desc

if
(this.ViewState["SortDirection"] == null)
{
this.ViewState["SortDirection"] = " DESC"
this
.ViewState["SortExpression"] = string.Empty;
}

//set the datasource

if
(this.DataSource != null && this.DataSource is DataSet)
{
//
this
.DataSource = ((DataSet)this.DataSource).Tables[this.DataMember.ToString()].DefaultView;
//

if
(!(this.CurrentPageIndex <= (((DataView)this.DataSource).Table.Rows.Count / this.PageSize)))
{
this.CurrentPageIndex = 0;
}
}
//else

//{

//            this.CurrentPageIndex = 0;

//}

#region
Set the Stylesheet styles
//Set the Stylesheet styles

//CAT

if
(this.StyleSheet == StyleSheetType.CAT)
{
this.CssClass = "CATDataGridStyle"
this
.HeaderStyle.CssClass = "CATDataGridHeaderStyle"
this
.ItemStyle.CssClass = "CATDataGridItemStyle"
this
.AlternatingItemStyle.CssClass = "CATDataGridAlternatingStyle"
this
.SelectedItemStyle.CssClass = "CATDataGridSelectedItemStyle"
this
.FooterStyle.CssClass = "CATDataGridFooterStyle"
}
//Default

else
if (this.StyleSheet == StyleSheetType.Default)
{
this.CssClass = "DefaultDataGrid"
this
.ItemStyle.CssClass = "DefaultDataGridItemStyle"
this
.AlternatingItemStyle.CssClass = "DefaultDataGridAlternatingStyle"
this
.HeaderStyle.CssClass = "DefaultDataGridHeaderStyle"
this
.SelectedItemStyle.CssClass = "DefaultDataGridSelectedItemStyle"
}
#endregion
#region
Adding Edit Item Template Column
//if the edit link is visible and edit on double click is enabled

//add the edit column

if
(this.EditVisible || this.EditOnDoubleClick)
{
EditCommandColumn editCommandColumn = new EditCommandColumn();
editCommandColumn.ButtonType = ButtonColumnType.LinkButton;
if
(this.ControlCaption == CaptionType.Text)
{
editCommandColumn.EditText = "Edit"
editCommandColumn.UpdateText = "Apply"
editCommandColumn.CancelText = "Cancel"
}
else

{
editCommandColumn.ItemStyle.Font.Size = 11;
editCommandColumn.ItemStyle.Font.Name = "wingdings 2"
editCommandColumn.EditText = "/"
editCommandColumn.UpdateText = "R"
editCommandColumn.CancelText = "T"
}
this
.Columns.Add(editCommandColumn);
this
.Columns[this.Columns.Count - 1].Visible = this.EditVisible;
}
#endregion
#region
Adding Delete Item Template Column
//add the delete column

ButtonColumn
deleteColumn = new ButtonColumn();
deleteColumn.CommandName = "delete"
if
(this.ControlCaption == CaptionType.Text)
{
deleteColumn.Text = "Delete"
}
else

{
deleteColumn.ItemStyle.Font.Size = 11;
deleteColumn.ItemStyle.Font.Name = "webdings"
deleteColumn.Text = "r"
}
this
.Columns.Add(deleteColumn);
this
.Columns[this.Columns.Count - 1].Visible = this.DeleteVisible;
#endregion

//if the data source is not null, add the template column to each column

if
(this.DataSource != null)
{
this.SetColumnsCollection();
//HttpContext.Current.Session["DataSource"] = this.DataSource;

//HttpContext.Current.Session["DataMember"] = this.DataMember;
}

#region
Adding ClientSide Script For SelectOnsingleClick etc...
string
scriptString;
#region
if the select on single click is true Set the OnClick Event of the grid
//if the select on single click is true Set the OnClick Event of the grid

if
(this.SelectOnSingleClick)
{
//write the script for onclick
scriptString = "<Script>"
scriptString += "var " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex;"
scriptString += "var " + this.UniqueID.Replace(":", "_") + "SelectedItemStyle;"
if
(this.DataSource != null && ((System.Data.DataView)this.DataSource).Table.Rows.Count > 0)
{
scriptString += this.UniqueID.Replace(":", "_") + "SelectedItemStyle='" + this.ItemStyle.CssClass + "';"
//                            //Code commented due to a bug, the bug still exists

if
(this.KeyHiddenControlId != null && ((System.Web.UI.HtmlControls.HtmlInputHidden)this.Page.FindControl(this.KeyHiddenControlId)) != null)
{
if (((System.Web.UI.HtmlControls.HtmlInputHidden)this.Page.FindControl(this.KeyHiddenControlId)).Value.Equals(String.Empty))
((System.Web.UI.HtmlControls.HtmlInputHidden)this.Page.FindControl(this.KeyHiddenControlId)).Value = ((System.Data.DataView)this.DataSource).Table.Rows[0].ItemArray[0].ToString();
}
if
(this.AllowPaging && this.PagerStyle.Position == PagerPosition.TopAndBottom)
{
this.Page.RegisterStartupScript(this.UniqueID.Replace(":", "_") + "SelectFirstElement", "<Script> try{" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex=document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[2].id; " + this.UniqueID.Replace(":", "_") + "SelectedItemStyle = document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[2].className; document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[2].className='" + this.SelectedItemStyle.CssClass + "';} catch (e) {} </Script>");
}
else

{
this.Page.RegisterStartupScript(this.UniqueID.Replace(":", "_") + "SelectFirstElement", "<Script> try{" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex=document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[1].id; " + this.UniqueID.Replace(":", "_") + "SelectedItemStyle = document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[1].className; document.getElementById('" + this.UniqueID.Replace(":", "_") + "').rows[1].className='" + this.SelectedItemStyle.CssClass + "';} catch (e) {} </Script>");
}


//this.Page.RegisterStartupScript(this.UniqueID.Replace(":","_") + "ScrolltoElement","<Script> document.getElementById(" + this.UniqueID.Replace(":","_") + "SelectedItemIndex).scrollIntoView(false); </Script>");
}
else
scriptString += this.UniqueID.Replace(":", "_") + "SelectedItemIndex='1';"
scriptString += " function " + this.UniqueID.Replace(":", "_") + "SelectMe()"
scriptString += " {"
scriptString += " try {"
scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != event.srcElement.parentElement.id && event.srcElement.parentElement.id!='')"
scriptString += " {"
//if(this.FullEditable) scriptString += "alert(" + this.UniqueID.Replace(":","_") + "SelectedItemIndex);"

//                      scriptString += "//Set Previously Selected Row to Alternating Style"

scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != '1')"
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className=" + this.UniqueID.Replace(":", "_") + "SelectedItemStyle;"
//                      scriptString += "//Set Currently Selected Row to Selected Style"

scriptString += " " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex = event.srcElement.parentElement.id;"
if
(this.KeyHiddenControlId != null)
scriptString += " document.getElementById('" + this.KeyHiddenControlId + "').value = " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex;"
scriptString += this.UniqueID.Replace(":", "_") + "SelectedItemStyle = event.srcElement.parentElement.className;"
if
(this.StyleSheet == StyleSheetType.CAT)
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className='CATDataGridSelectedItemStyle';"
if (this.StyleSheet == StyleSheetType.Default)
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className='DefaultDataGridSelectedItemStyle';"
scriptString += "}"

//enhanced for druv to allow checkbox click selection of row

scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != event.srcElement.parentElement.parentElement.id && event.srcElement.parentElement.parentElement.id!='')"
scriptString += " {"
//                      scriptString += "//Set Previously Selected Row to Alternating Style"

scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != '1')"
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className=" + this.UniqueID.Replace(":", "_") + "SelectedItemStyle;"
//                      scriptString += "//Set Currently Selected Row to Selected Style"

scriptString += " " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex = event.srcElement.parentElement.parentElement.id;"
if
(this.KeyHiddenControlId != null)
scriptString += " document.getElementById('" + this.KeyHiddenControlId + "').value = " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex;"
scriptString += this.UniqueID.Replace(":", "_") + "SelectedItemStyle = event.srcElement.parentElement.parentElement.className;"
//                                                                                                                                                

if
(this.StyleSheet == StyleSheetType.CAT)
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className='CATDataGridSelectedItemStyle';"
if (this.StyleSheet == StyleSheetType.Default)
scriptString += " document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).className='DefaultDataGridSelectedItemStyle';"
scriptString += "}"
scriptString += "}"
scriptString += "catch (e) {}"
scriptString += "}"
scriptString += " </Script>"
//register the script

this
.Page.RegisterClientScriptBlock(this.UniqueID.Replace(":", "_") + "SelectMe", scriptString);
}
#endregion
#region
if the edit on double click is true, Set the doubleClick Event of the grid
//if the edit on double click is true, Set the doubleClick Event of the grid

if
(this.EditOnDoubleClick && this.AllowEdit == EditType.UnAuthorized)
{
//Set the OndblClick Event of the grid
scriptString = "<Script>"
scriptString += " function " + this.UniqueID.Replace(":", "_") + "OpenMe()"
scriptString += " {"
scriptString += " }"
scriptString += " </Script>"
this
.Page.RegisterClientScriptBlock(this.UniqueID.Replace(":", "_") + "OpenMe", scriptString);
}
if
(this.EditOnDoubleClick && this.AllowEdit != EditType.UnAuthorized)
{
//Set the OndblClick Event of the grid
scriptString = "<Script>"
if
(!this.SelectOnSingleClick)
scriptString += "var " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex;"
scriptString += " function " + this.UniqueID.Replace(":", "_") + "OpenMe()"
scriptString += " {"
if
(!this.SelectOnSingleClick)
scriptString += " " + this.UniqueID.Replace(":", "_") + "SelectedItemIndex = event.srcElement.parentElement.id;"
scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != '1'){"
scriptString += " var callEdit=new Function(document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).onedit);"
scriptString += " callEdit();"
scriptString += " }}"
scriptString += " </Script>"
this
.Page.RegisterClientScriptBlock(this.UniqueID.Replace(":", "_") + "OpenMe", scriptString);
}
#endregion
#region
Call Delete Event of the Selected Item
//Call Delete Event of the Selected Item

scriptString = "<Script>"
scriptString += " function " + this.UniqueID.Replace(":", "_") + "DeleteMe()"
scriptString += " {"
scriptString += " var status=confirm('" + Resource.Application.DeleteConfirmationMessage + "');"
scriptString += " if (!status) return;"
scriptString += " if (" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex != '1'){ "
scriptString += " var callDelete=new Function(document.getElementById(" + this.UniqueID.Replace(":", "_") + "SelectedItemIndex).onDelete);"
scriptString += " callDelete();"
scriptString += " } }"
scriptString += " </Script>"
this
.Page.RegisterClientScriptBlock(this.UniqueID.Replace(":", "_") + "DeleteMe", scriptString);
#endregion
#endregion

//this.DataBind();

if
(this.ViewState["SortExpression"].ToString().Length != 0)
((DataView)this.DataSource).Sort = this.ViewState["SortExpression"].ToString() + this.ViewState["SortDirection"].ToString();
}
///
<summary>
/// Gets Fired Each Time The DataGrid Is Processded

///
</summary>
///
<param name="e"></param>
protected
override void OnItemCreated(DataGridItemEventArgs e)
{
base.OnItemCreated(e);

if
(e.Item.ItemType == ListItemType.Pager)
{
// Extract the Pager
TableCell
pager = (TableCell)e.Item.Controls[0];
pager.HorizontalAlign = HorizontalAlign.Left;

//Add Cell to Row to Hold Row Count Label

//                                                                TableCell newcell = new TableCell();

//                                                                newcell.HorizontalAlign = HorizontalAlign.Right;

//Add Label Indicating Row Count

Label
lblNumRecords = new Label();
lblNumRecords.CssClass = "LabelStyle"
lblNumRecords.ID = "lblNumRecords"
pager.Controls.Add(lblNumRecords);

Table
pagerTable = new Table();
pagerTable.Width = Unit.Percentage(100);
pagerTable.Rows.Add(new TableRow());
pagerTable.Rows[0].CssClass = e.Item.CssClass;
pagerTable.Rows[0].Cells.Add(pager);
//                                                                pagerTable.Rows[0].Cells.Add(newcell);

e.Item.Controls.Add(new TableCell());
((TableCell)e.Item.Controls[0]).ColumnSpan = pager.ColumnSpan;
e.Item.Controls[0].Controls.Add(pagerTable);

try

{
for (int ictr = 0; ictr < pager.Controls.Count; ictr = ictr + 2)
{
if (pager.Controls[ictr].GetType().ToString() == "System.Web.UI.WebControls.Label")
((Label)pager.Controls[ictr]).CssClass = "LabelStyle"
else
((LinkButton)pager.Controls[ictr]).CssClass = "LabelStyle"
}
}
catch

{
}
}
}
///
<summary>
/// Method to handle the ItemDataBound event of the EMS Datagrid

///
</summary>
///
<param name="e"></param>
protected
override void OnItemDataBound(DataGridItemEventArgs e)
{
#region From This Part Implements EMS 1.0 Written Amith
//Set the Sort Glyph

if
(e.Item.ItemType == ListItemType.Header && this.ViewState["SortExpression"] != null)
{
//if there is a value for sort
if
(this.ViewState["SortExpression"].ToString().Length != 0)
{
for (int i = 0; i < this.Columns.Count; i++)
{
if (this.ViewState["SortExpression"].ToString() == Columns[i].SortExpression)
{
Label lblSorted = new Label();
lblSorted.Font.Name = "webdings"
lblSorted.Font.Size = FontUnit.XSmall;
if
(this.ViewState["SortDirection"].ToString() == " ASC")
lblSorted.Text = "6"
else
lblSorted.Text = "5"
e.Item.Cells[i].Controls.Add(lblSorted);
}
}
}
}

//only for items and alternating items

if
(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//add the primary key as the row id for each row to support single click
if
(((DataRowView)e.Item.DataItem).DataView.Table.PrimaryKey.Length != 0)
e.Item.Attributes.Add("ID", ((DataRowView)e.Item.DataItem).Row[((DataRowView)e.Item.DataItem).DataView.Table.PrimaryKey[0].ColumnName.ToString()].ToString());
else
e.Item.Attributes.Add("ID", ((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString());
if (this.SelectOnSingleClick)
//set single click attribute to the row
e.Item.Attributes.Add("onclick", this.UniqueID.Replace(":", "_") + "SelectMe(); document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';");

if ((this.EditVisible || this.EditOnDoubleClick) && e.Item.Cells[0].Controls.Count > 0)
{
LinkButton editbutton = (LinkButton)e.Item.Cells[0].Controls[0];
//Set the tooltip if the captionstyle is graphics

if
(this.ControlCaption == CaptionType.Graphics)
editbutton.ToolTip = "Edit"
//Set double click attribute to the row, which is enter edit mode
if
(this.EditOnDoubleClick)
{
e.Item.Attributes.Add("ondblClick", this.UniqueID.Replace(":", "_") + "OpenMe();; document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';");
//this is to pass the selected item id as an argument to the event.

editbutton.CommandArgument = e.Item.Attributes["ID"];
e.Item.Attributes.Add("onedit", Page.GetPostBackClientHyperlink(editbutton, e.Item.Attributes["ID"]) + " document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';");
}
}
//                

if
(this.DeleteVisible && this.AllowDelete == DeleteType.DeleteWithConfirmation && e.Item.Cells[1].Controls.Count > 0)
{
LinkButton deletebutton = null;
//

if
(e.Item.Cells[1].Controls[0] is LinkButton)
{
deletebutton = (LinkButton)e.Item.Cells[1].Controls[0];
}
else
if (e.Item.Cells[0].Controls[0] is LinkButton)
{
deletebutton = (LinkButton)e.Item.Cells[0].Controls[0];
}
//                                                                                                                                                                

if
(!object.Equals(deletebutton, null))
{
//Set the tooltip if the captionstyle is graphics
if
(this.ControlCaption == CaptionType.Graphics)
deletebutton.ToolTip = "Delete"
//Set a popup confirmation box attribute if delete needs a confirmation
if
(this.AllowDelete == DeleteType.DeleteWithConfirmation)
{
deletebutton.Attributes["onclick"] = "return confirm('" + Resource.Application.DeleteConfirmationMessage + "'); document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';"
}
deletebutton.CommandArgument = e.Item.Attributes["ID"];
e.Item.Attributes.Add("onDelete", Page.GetPostBackClientHyperlink(deletebutton, e.Item.Attributes["ID"]) + " document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';");
}
}
try

{
LinkButton deletebutton;
if
(this.editOnDoubleClick)
{
deletebutton = (LinkButton)e.Item.Cells[1].Controls[0];
}
else

{
deletebutton = (LinkButton)e.Item.Cells[0].Controls[0];
}
//this is to pass the selected item id as an argument to the event.

deletebutton.CommandArgument = e.Item.Attributes["ID"];
e.Item.Attributes.Add("onDelete", Page.GetPostBackClientHyperlink(deletebutton, e.Item.Attributes["ID"]) + " document.forms[0].item(\"" + this.strConcurrencyIdControl + "\").value='" + e.Item.Attributes["ID"] + "';");
}
catch

{
//Nothing to do if the first control in the first column is not linkbutton.
}
}
#endregion
#region
From This Part Implements EMS 2.0 Written Yasin

if
(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
if (this.FullEditable)
{
//
DataTable
dt = ((DataView)this.DataSource).Table;
//this.BindServerControl(e.Item, 0, e.Item.ItemIndex, dt.Rows[e.Item.ItemIndex], dt.Columns, dt.Columns.Count);

this
.SetDropDownSelectedValue(e, 1);
//

this
.SetRowColumnReadOnly(e.Item, 1, e.Item.ItemIndex, dt.Rows[e.Item.ItemIndex], dt.Columns, dt.Columns.Count);
//

this
.AddValidatorControl(e, 1);
//

this
.AddMultipleControls(e, 1);
//

this
.AddDateControl(e, 1);
//

this
.FormatGridCell(e, 1);
}
else
if (this.EnhanceEdit)
{
if (this.EditItemIndex != -1 && this.EditItemIndex == e.Item.ItemIndex)
{
//
DataTable
dt = ((DataView)this.DataSource).Table;
//

this
.BindServerControl(e.Item, 2, e.Item.ItemIndex, dt.Rows[e.Item.ItemIndex], dt.Columns, dt.Columns.Count);
//

this
.AddValidatorControl(e, 2);
//

this
.AddMultipleControls(e, 2);
//

this
.AddDateControl(e, 2);
//Removing The Delete Button Link Incase of Edit Mode

if
(e.Item.Cells[1].Controls[0] is LinkButton)
{
e.Item.Cells[1].Controls[0].Visible = false;
}
}
else

{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
DataTable dt = ((DataView)this.DataSource).Table;
if
(e.Item.ItemIndex < dt.Rows.Count)
{
this.BindServerControl(e.Item, 2, e.Item.ItemIndex, dt.Rows[e.Item.ItemIndex], dt.Columns, dt.Columns.Count);
}
}
}
this
.FormatGridCell(e, 2);
}
else

{
this.FormatGridCell(e, 2);
}
}

//Adding The Feature Of CheckBoxState

if
(this.blnCheckBoxState)
{
this.AddCheckBoxState(e);
}
#endregion

base
.OnItemDataBound(e);
}
///
<summary>
/// Get Fired to Before The HTML Content Is Rendered

///
</summary>
///
<param name="e"></param>
protected
override void OnPreRender(EventArgs e)
{
if ((this.AllowPaging || this.AllowCustomPaging) && !Object.Equals(this.DataSource, null))
{
int startRecord = (this.CurrentPageIndex * this.PageSize) + 1;
int
endRecord = (startRecord + this.PageSize) - 1;
if
(((DataView)this.DataSource).Count < endRecord)
endRecord = ((DataView)this.DataSource).Count;
int totalRecord = ((DataView)this.DataSource).Count;
//Set the top pager

((Label)this.Controls[0].Controls[0].FindControl("lblNumRecords")).Text = "&nbsp;&nbsp;&nbsp;Records " + startRecord.ToString() + " to " + endRecord.ToString() + " of " + totalRecord.ToString();
//Clear the bottom pager

((Label)this.Controls[0].Controls[this.Controls[0].Controls.Count - 1].FindControl("lblNumRecords")).Text = ""
//

if
(((DataView)this.DataSource).Count == 0)
{
//TODO: Localization - Amith Ellur
((Label)this.Controls[0].Controls[0].FindControl("lblNumRecords")).Text = "There are no records to be displayed."
this
.Controls[0].Controls.Remove(this.Controls[0].Controls[1]);
this
.Controls[0].Controls.Remove(this.Controls[0].Controls[2]);
this
.Controls[0].Controls[0].Controls[0].Controls[0].Controls[0].Controls.Remove(this.Controls[0].Controls[0].Controls[0].Controls[0].Controls[0].Controls[0]);
this
.BorderColor = Color.Transparent;
this
.BorderStyle = BorderStyle.None;
}
//Adding The ClientSide Scripts For CheckBoxState

if
(this.blnCheckBoxState)
{
this.AddClientSideScript();
}
}

//

if
(this.Items.Count > 0)
{
//
this
.hidConcurrencyIdControl.ID = HIDDENCONCURRENCYIDCONCTROL;
//

this
.hidConcurrencyIdControl.Value = this.Items[0].Attributes["ID"];
//

this
.Controls.Add(this.hidConcurrencyIdControl);
}


//Adding The Focus On The Editted Item Control

//                                    if(this.EnhanceEdit)

//                                    {

//                                                bool blnFocus = false;

//                                                for(int item = 0; item < this.Items.Count; item++)

//                                                {

//                                                            if(this.Items[item].ItemType == ListItemType.EditItem)

//                                                            {

//                                                                        for(int cell = 0; cell < this.Items[item].Cells.Count; cell++)            

//                                                                        {

//                                                                                    if(this.Items[item].Cells[cell].Visible)

//                                                                                    {

//                                                                                                for(int control = 0; control < this.Items[item].Cells[cell].Controls.Count; control++)

//                                                                                                {

//                                                                                                            if(this.Items[item].Cells[cell].Controls[control] is TextBox)

//                                                                                                            {

//                                                                                                                        if(!((TextBox)this.Items[item].Cells[cell].Controls[control]).ReadOnly)

//                                                                                                                        {

//                                                                                                                                    this.Page.RegisterClientScriptBlock("focus", "<script>document.forms[0].item(\"" + ((TextBox)this.Items[item].Cells[cell].Controls[control]).ClientID + "\").focus()</script>");

//                                                                                                                                    blnFocus = true;

//                                                                                                                                    break;

//                                                                                                                                                

//                                                                                                                        }

//                                                                                                            }

//                                                                                                            else if(this.Items[item].Cells[cell].Controls[control] is DropDownList)

//                                                                                                            {

//                                                                                                                        this.Page.RegisterClientScriptBlock("focus", "<script>document.forms[0].item(\"" + ((DropDownList)this.Items[item].Cells[cell].Controls[control]).ClientID + "\").focus()</script>");

//                                                                                                                        blnFocus = true;

//                                                                                                                        break;

//                                                                                                            }

//                                                                                                }

//                                                                                    }

//                                                                                    if(blnFocus) break;

//                                                                        }

//                                                            }

//                                                            if(blnFocus) break;

//                                                }

//                                    }                                    

base
.OnPreRender(e);
}
///
<summary>
///

///
</summary>
///
<param name="savedState"></param>
//protected override void LoadViewState(object savedState)

//{

//this.DataSource = HttpContext.Current.Cache["temp"];

//this.DataMember = HttpContext.Current.Cache["temp1"].ToString();

//this.DataBind();

//TODO: Yasin, This is where the columns controls should be added - Amith Ellur

//}

//protected override object SaveViewState()

//{

//HttpContext.Current.Cache["temp"]  = this.DataSource;

//HttpContext.Current.Cache["temp1"] = this.DataMember;

//this.ViewState;

//        return null;

//}

#endregion
#region
Events That Get Fired On Post Back When Edit, Delete, Sorting, Paging etc.. Get Fired
///
<summary>
/// Method to handle the PageIndexChanged event of the EMS Datagrid

///
</summary>
///
<param name="source"></param>
///
<param name="e"></param>
private
void EMSDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.WriteHiddenControl();
this
.EditItemIndex = -1;
this
.CurrentPageIndex = e.NewPageIndex;
this
.DataBind();
}
///
<summary>
/// Method to handle the CancelCommand event of the EMS Datagrid

///
</summary>
///
<param name="source"></param>
///
<param name="e"></param>
private
void EMSDataGrid_CancelCommand(object source, DataGridCommandEventArgs e)
{
this.EditItemIndex = -1;
this
.DataBind();
}
///
<summary>
/// Method to handle the EditCommand event of the EMS Datagrid

///
</summary>
///
<param name="source"></param>
///
<param name="e"></param>
private
void EMSDataGrid_EditCommand(object source, DataGridCommandEventArgs e)
{
try
{
//Calling The Helper Function To Validate If The Record Exists In The Grid
this
.ValidateConcurrencyControl(e.Item.Attributes["ID"]);
//if inline edit, hide the delete column

if
(this.AllowEdit == EditType.InLine)
{
//this.EditItemIndex = e.Item.ItemIndex;
ToggleDeleteColumn(false);
this
.DataBind();
}
//if not inline edit, then redirect to the selected page

else
if (this.AllowEdit == EditType.PageRedirect)
{
OnEditPage(e);
}
}
catch
(Exception exception)
{
this.ProcessException(exception);
}
}
///
<summary>
/// Method to handle the UpdateCommand event of the EMS Datagrid

///
</summary>
///
<param name="source"></param>
///
<param name="e"></param>
private
void EMSDataGrid_UpdateCommand(object source, DataGridCommandEventArgs e)
{
//Validating If Ehance Edit Is True
if
(this.EnhanceEdit)
{
//Calling The Helper Function For Updating The Specific Data Row From DataGrid Row Values
this
.ReadDataGridData(e.Item.ItemIndex);
//Creating A DataTable From The Default DataView

DataTable
dt = ((DataView)this.DataSource).Table;
//Declaring the PK

DataColumn
[] prk = dt.PrimaryKey;
//Coping the DataRow

DataRow
dr = dt.Rows[e.Item.ItemIndex];
//Iterating Through the Primary Keys To Set The New Guid Incase A New Record Is Added

for
(int dclength = 0; dclength < prk.Length; dclength++)
{
//Validating if the primary is blank
if
(object.Equals(dr[prk[dclength].Ordinal], DBNull.Value))
{
//Validating if the primary is readonly
if
(dt.Columns[prk[dclength].ColumnName].ReadOnly)
{
//Updating the New Guid for the PK
dt.Columns[prk[dclength].ColumnName].ReadOnly = false;
dr[prk[dclength].ColumnName] = Guid.NewGuid();
dt.Columns[prk[dclength].ColumnName].ReadOnly = true;
}
}
}

//Iterating Through the DataColums To Set The Default Values For The New Data Row

for
(int dclength = 0; dclength < dt.Columns.Count; dclength++)
{
//Validating if the column is readonly
if
(dt.Columns[dclength].ReadOnly)
{
//Validating if the data columns value is dbnull
if
(object.Equals(dr[dclength], DBNull.Value))
{
//Updating the default value
dt.Columns[dclength].ReadOnly = false;
dr[dclength] = dt.Columns[dclength].DefaultValue;
dt.Columns[dclength].ReadOnly = true;
}
}
}
//Copying the Structure of the datatable

this
.dtModifiedDataTable = dt.Clone();
//Adding A new Row

DataRow
newdr = this.dtModifiedDataTable.NewRow();
//Iterating To The Columns of the datarow

for
(int i = 0; i < dr.ItemArray.Length; i++)
{
//Updating Data Into New Column
newdr[i] = dr.ItemArray[i];
}
//Adding The New DataRow

this
.dtModifiedDataTable.Rows.Add(newdr);
}
//base.OnUpdateCommand(e);

//show the delete column of the datagrid

ToggleDeleteColumn(true);
}
///
<summary>
/// Method to handle the SortCommand event of the EMS Datagrid

///
</summary>
///
<param name="source"></param>
///
<param name="e"></param>
private
void EMSDataGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
{
this.ViewState["SortExpression"] = e.SortExpression;

//Change the sort direction for next use.

if
(this.ViewState["SortDirection"].ToString() == " DESC")
this.ViewState["SortDirection"] = " ASC"
else
this.ViewState["SortDirection"] = " DESC"
// The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.

((DataView)this.DataSource).Sort = e.SortExpression + this.ViewState["SortDirection"];

// Rebind the data source and specify that it should be sorted

// by the field specified in the SortExpression property.

this
.DataBind();
}

///
<summary>
///

///
</summary>
///
<param name="e"></param>
protected
override void OnDeleteCommand(DataGridCommandEventArgs e)
{
try
{
// If First item in the row, one page back
if
(this.Items.Count == 1)
this.CurrentPageIndex = (this.CurrentPageIndex == 0 ? 0 : this.CurrentPageIndex - 1);
//Calling The Helper Function To Validate If The Record Exists In The Grid
this
.ValidateConcurrencyControl(e.Item.Attributes["ID"]);
base
.OnDeleteCommand(e);
}
catch
(Exception exception)
{
//Calling The Helper Function
this
.ProcessException(exception);
}
}
///
<summary>
/// This Helper Function Rasies The EMSDataGridRaiseException Event

///
</summary>
///
<param name="exception"></param>
private
void ProcessException(Exception exception)
{
//Validating If The Caller Has Implemented The Event
if
(!object.Equals(this.EMSDataGridRaiseException, null))
{
this.EMSDataGridRaiseException(this, exception);
}
else

{
throw exception;
}
}

///
<summary>
/// Used For Page Redirect

///
</summary>
///
<param name="e"></param>
protected
virtual void OnEditPage(DataGridCommandEventArgs e)
{
if (EditPage != null)
EditPage(this, e);
}
#endregion
#endregion
#region
Helper Functions Used In Class
///
<summary>
/// Show/Hide the DELETE column when in edit mode. This handles the visibility of Delete column based on DeleteVisible property

///
</summary>
///
<param name="bViewState"></param>
private
void ToggleDeleteColumn(bool bViewState)
{
if (!this.DeleteVisible)
Columns[1].Visible = bViewState;
}
///
<summary>
/// This Helper function Is Called In The Page Index Changed Event To Store The Checked Records In The Dataset From The Hidden Control

///
</summary>
///
<param name="?"></param>
///
<returns></returns>
private
void WriteHiddenControl()
{
if (this.blnCheckBoxState)
{
//
if
(this.DataSource == null && this.DataSource is DataSet)
{
return;
}
//

string
strHidden = HttpContext.Current.Request[this.strHiddenCheckBoxState];
//Validating If The user has checked any records

if
(strHidden.Length > 0)
{
//Validating If The ViewState Exists For This Object
if
(object.Equals(this.ViewState[this.strHiddenCheckBoxState], null))
{
//Creating The DataTable
DataTable
dtCheckBoxState = new DataTable(this.DataMember.ToString());
//Adding Columns To The DataTable

dtCheckBoxState.Columns.Add(new DataColumn("PageNumber", System.Type.GetType("System.Int64")));
dtCheckBoxState.Columns.Add(new DataColumn("Id", System.Type.GetType("System.Guid")));
//Splitting The Strings

string
[] spliter = strHidden.Split(new char[1] { '~' });
string
[] strId = spliter[1].Split(new char[1] { '^' });
//Adding The Newly Checked Records Into The DataTable

for
(int i = 0; i < strId.Length; i++)
{
//
DataView
dv = ((DataView)this.DataSource);
//

DataColumn
[] dc = dv.Table.PrimaryKey;
//

if
(dc.Length == 1)
{
//
DataRow
[] DataRowSearch = dv.Table.Select(dc[0].ColumnName + "='" + strId[i] + "'");
//

if
(DataRowSearch.Length == 1)
{
DataRow drCheckBoxState = dtCheckBoxState.NewRow();
dtCheckBoxState.Rows.Add(drCheckBoxState);
drCheckBoxState["PageNumber"] = spliter[0];
drCheckBoxState["Id"] = strId[i];
}
}
else

{
throw new Exception("No Primary Key Set For Binded DataTable " + dv.Table.TableName);
}
}
//Creating the Instance Of The DataSet

this
.dsCheckBoxState = new DataSet();
//Adding the DataTable To The DataSet

this
.dsCheckBoxState.Tables.Add(dtCheckBoxState);
}
else

{
//Creating The Instance Of The DataSet
this
.dsCheckBoxState = new DataSet();
//Creating The Instance of StringReader Class

StringReader
sr = new StringReader(this.ViewState[this.strHiddenCheckBoxState].ToString());
//Loading The DataSet From StringReader Class

this
.dsCheckBoxState.ReadXml(sr);
//Fetching The datatable from the dataset

DataTable
dtCheckBoxState = this.dsCheckBoxState.Tables[this.DataMember.ToString()];
//Splitting The Strings

string
[] spliter = strHidden.Split(new char[1] { '~' });
//Filtering The DataTable Based on DataRows

DataRow
[] dr = dtCheckBoxState.Select("PageNumber" + "='" + strHidden[0] + "'");
//Removing The DataRows Which Were Affected From The DataTable.Select Method

for
(int drCtr = 0; drCtr < dr.Length; drCtr++)
{
dtCheckBoxState.Rows.Remove(dr[drCtr]);
}
//                        

if
(spliter.Length == 2)
{
//
string
[] strId = spliter[1].Split(new char[1] { '^' });
//Checking The DataRow Length

if
(dr.Length == 0)
{
//Adding The Newly Checked Records Into The DataTable
for
(int i = 0; i < strId.Length; i++)
{
//
DataView
dv = ((DataView)this.DataSource);
//

DataColumn
[] dc = dv.Table.PrimaryKey;

if
(dc.Length == 1)
{
//
DataRow
[] DataRowSearch = dv.Table.Select(dc[0].ColumnName + "='" + strId[i] + "'");
//

if
(DataRowSearch.Length == 1)
{
DataRow drCheckBoxState = dtCheckBoxState.NewRow();
dtCheckBoxState.Rows.Add(drCheckBoxState);
drCheckBoxState["PageNumber"] = spliter[0];
drCheckBoxState["Id"] = strId[i];
}
}
else

{
throw new Exception("No Primary Key Set For Binded DataTable " + dv.Table.TableName);
}
}
}
else

{
//Adding The Newly Checked Records Into The DataTable
for
(int i = 0; i < strId.Length; i++)
{
//
DataView
dv = ((DataView)this.DataSource);
//

DataColumn
[] dc = dv.Table.PrimaryKey;

if
(dc.Length == 1)
{
//
DataRow
[] DataRowSearch = dv.Table.Select(dc[0].ColumnName + "='" + strId[i] + "'");
//

if
(DataRowSearch.Length == 1)
{
DataRow drCheckBoxState = dtCheckBoxState.NewRow();
dtCheckBoxState.Rows.Add(drCheckBoxState);
drCheckBoxState["PageNumber"] = spliter[0];
drCheckBoxState["Id"] = strId[i];
}
}
else

{
throw new Exception("No Primary Key Set For Binded DataTable " + dv.Table.TableName);
}
}
}
}
}
//Storing The DataSet Into ViewState

//TODO: Amith Please Check This Option And Get Back

if
(this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
this.ViewState[this.strHiddenCheckBoxState] = this.dsCheckBoxState.GetXml();
}
this
.intNoOfRecordsCheckBoxState = this.dsCheckBoxState.Tables[0].Rows.Count;
}
else

{
if (!object.Equals(HttpContext.Current.Request[this.strHiddenPreviousPage], null) && !object.Equals(this.ViewState[this.strHiddenCheckBoxState], null))
{
//Creating The Instance Of The DataSet
this
.dsCheckBoxState = new DataSet();
//Creating The Instance of StringReader Class

StringReader
sr = new StringReader(this.ViewState[this.strHiddenCheckBoxState].ToString());
//Loading The DataSet From StringReader Class

this
.dsCheckBoxState.ReadXml(sr);
//Fetching The datatable from the dataset

DataTable
dtCheckBoxState = this.dsCheckBoxState.Tables[this.DataMember.ToString()];
//Filtering The DataTable Based on DataRows

DataRow
[] dr = dtCheckBoxState.Select("PageNumber" + "='" + HttpContext.Current.Request[this.strHiddenPreviousPage] + "'");
//Removing The DataRows Which Were Affected From The DataTable.Select Method

for
(int drCtr = 0; drCtr < dr.Length; drCtr++)
{
dtCheckBoxState.Rows.Remove(dr[drCtr]);
}
//Storing The DataSet Into ViewState

//TODO: Amith Please Check This Option And Get Back

if
(this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
this.ViewState[this.strHiddenCheckBoxState] = this.dsCheckBoxState.GetXml();
}
else

{
this.ViewState.Remove(this.strHiddenCheckBoxState);
}
}
//

if
(!object.Equals(HttpContext.Current.Request[this.strCheckBoxStateCount], null))
{
//
if
(HttpContext.Current.Request[this.strCheckBoxStateCount].Trim().Length > 0)
{
this.intNoOfRecordsCheckBoxState = int.Parse(HttpContext.Current.Request[this.strCheckBoxStateCount].Trim());
}
}
}
}
}
///
<summary>
/// Helper function Is used To Set The Various Item Template For The Grid

///
</summary>
private
void SetColumnsCollection()
{
//TODO: Remove - Yasin
string
strCellName;

int
ctr;
//

if
(this.EditOnDoubleClick && this.selectOnSingleClick)
{
ctr = 2;
}
else

{
ctr = 1;
}
//

foreach
(DataColumn col in ((DataView)this.DataSource).Table.Columns)
{
strCellName = this.NamingContainer.ID + "_" + this.ID + "_row" + this.Items.Count + "_ctr" + col.Ordinal.ToString();

this
.PropertyCollection = col.ExtendedProperties;

TemplateColumn
tc1 = new TemplateColumn();

if
(this.intCheckBoxColumn == ctr)
{
tc1.HeaderTemplate = new
DataGridTemplate(ListItemType.Header, col.ColumnName, col.Caption, col.Ordinal, col.DataType.ToString(), this.AllowSorting, this.HeaderStyle.CssClass, this.blnFullEdidtable, col.ReadOnly, this.PropertyCollection, col.AllowDBNull, this.blnEnhanceEdit, strCellName, col.MaxLength, this.blnCheckBoxState, this.intCheckBoxColumn);
}
else

{
tc1.HeaderTemplate = new
DataGridTemplate(ListItemType.Header, col.ColumnName, col.Caption, col.Ordinal, col.DataType.ToString(), this.AllowSorting, this.HeaderStyle.CssClass, this.blnFullEdidtable, col.ReadOnly, this.PropertyCollection, col.AllowDBNull, this.blnEnhanceEdit, strCellName, col.MaxLength, false, this.intCheckBoxColumn);
}

tc1.ItemTemplate = new
DataGridTemplate(ListItemType.Item, col.ColumnName, col.Caption, col.Ordinal, col.DataType.ToString(), this.AllowSorting, this.HeaderStyle.CssClass, this.blnFullEdidtable, col.ReadOnly, this.PropertyCollection, col.AllowDBNull, this.blnEnhanceEdit, strCellName, col.MaxLength, this.blnCheckBoxState, this.intCheckBoxColumn);
tc1.EditItemTemplate = new
DataGridTemplate(ListItemType.EditItem, col.ColumnName, col.Caption, col.Ordinal, col.DataType.ToString(), this.AllowSorting, this.HeaderStyle.CssClass, this.blnFullEdidtable, col.ReadOnly, this.PropertyCollection, col.AllowDBNull, this.blnEnhanceEdit, strCellName, col.MaxLength, this.blnCheckBoxState, this.intCheckBoxColumn);
tc1.FooterTemplate = new
DataGridTemplate(ListItemType.Footer, col.ColumnName, col.Caption, col.Ordinal, col.DataType.ToString(), this.AllowSorting, this.HeaderStyle.CssClass, this.blnFullEdidtable, col.ReadOnly, this.PropertyCollection, col.AllowDBNull, this.blnEnhanceEdit, strCellName, col.MaxLength, this.blnCheckBoxState, this.intCheckBoxColumn);
tc1.SortExpression = col.ColumnName;

if
(!Object.Equals(col.ExtendedProperties[EMSDataGridExtendedProperties.Visibility], null))
{
tc1.Visible = (bool)col.ExtendedProperties[EMSDataGridExtendedProperties.Visibility];
}

this
.Columns.Add(tc1);
//

ctr++;
}
}

///
<summary>
///  This Helper Function Is Used For Validating If The Selected Records Exists In Post Backs

///
</summary>
///
<param name="strID"></param>
private
void ValidateConcurrencyControl(string strID)
{
if (!object.Equals(this.strConcurrencyIdControl, null))
{
if (strID != HttpContext.Current.Request[this.strConcurrencyIdControl])
{
throw new Exception("||Record Does Not Exisits In The System||");
}
}
}
///
<summary>
/// Helper Function Returns A DataTime Based On The Specific Format Used With Concurrency

///
</summary>
///
<param name="strDate"></param>
///
<returns></returns>
private
DateTime DateConvertorConcurrency(string strDate)
{
//TODO: Get It From The Ticket
return
DateTime.ParseExact(strDate, "dd/MM/yyyy HH:mm:ss:fff", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None);
}
///
<summary>
/// Helper Function Returns A String Based On The Specific Format Used With Concurrency

///
</summary>
///
<param name="dtDate"></param>
///
<returns></returns>
private
string DateConvertorConcurrency(DateTime dtDate)
{
return dtDate.ToString("dd/MM/yyyy HH:mm:ss:fff");
}
///
<summary>
/// Helper function Is Used To Format The Date Based On System Preferences

///
</summary>
///
<param name="dtDate"></param>
///
<returns></returns>
public
DateTime DateConvertor(string strDate)
{
//TODO: Get It From The Ticket
return
DateTime.ParseExact(strDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None);
}
///
<summary>
///  Helper function Is Used To Format The Date Based On System Preferences

///
</summary>
///
<param name="dtDate"></param>
///
<returns></returns>
public
string DateConvertor(DateTime dtDate)
{
return dtDate.ToString("dd/MM/yyyy");
}

///
<summary>
/// Helper function converts A DataRow Value into Date

///
</summary>
///
<param name="objDate"></param>
///
<returns></returns>
private
object GetValidDate(object objDate)
{
if (objDate.Equals(DBNull.Value))
{
return objDate;
}
else

{
return this.DateConvertor(objDate.ToString());
}
}
///
<summary>
/// Helper function converts A DataRow Value into Valid String Value

///
</summary>
///
<param name="strValue"></param>
///
<returns></returns>
private
object GetValidValue(string strValue)
{
strValue = strValue.ToString().Trim();
if
(strValue.Length == 0)
{
return DBNull.Value;
}
else

{
return strValue;
}
}
///
<summary>
/// Helper function converts A String Value Into A DataRow Value

///
</summary>
///
<param name="strControlValue"></param>
///
<returns></returns>
private
object SetValidDBValue(string strControlValue)
{
strControlValue = strControlValue.Trim();

if
(strControlValue.Length == 0)
{
return DBNull.Value;
}
else

{
return strControlValue;
}
}

///
<summary>
/// This helper function is called in the ItemDataBound Event to format the Item Cells based on the datatypes

///
</summary>
private
void FormatGridCell(DataGridItemEventArgs e, int cells)
{
try
{
DataTable dt = ((DataView)this.DataSource).Table;
for
(int i = 0; i < dt.Columns.Count; i++)
{
//Putting The Range Validator To Handle Arthi OverFlow Error
switch
(dt.Columns[i].DataType.ToString())
{
case "System.Guid": //UniqueIdentifier
break;
case "System.String": //varchar
e.Item.Cells[cells].HorizontalAlign = HorizontalAlign.Left;
break
;
case "System.Boolean": //Bit
e.Item.Cells[cells].HorizontalAlign = HorizontalAlign.Center;
break
;
case "System.Int64": //BigInt
//Right
goto
case "Numeric"
case "System.Decimal": //Decimal, Money, Numeric, SmallMoney
//Right
goto
case "Numeric"
case "System.Double": //Float
//Right
goto
case "Numeric"
case "System.Int32": //Int
//Right
goto
case "Numeric"
case "System.Int16": //smallInt
//Right
goto
case "Numeric"
case "System.Byte": //tinyInt
//Right
goto
case "Numeric"
case "System.DateTime": //DateTime
//Center
e.Item.Cells[cells].HorizontalAlign = HorizontalAlign.Center;
//Format Based

for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is Literal)
{
if (dt.Rows[e.Item.ItemIndex][i] != DBNull.Value)
{
((Literal)e.Item.Cells[cells].Controls[ctl]).Text = this.DateConvertor((DateTime)dt.Rows[e.Item.ItemIndex][i]);
}
break
;
}
else
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
if (dt.Rows[e.Item.ItemIndex][i] != DBNull.Value)
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).Text = this.DateConvertor((DateTime)dt.Rows[e.Item.ItemIndex][i]);
}
break
;
}
}
break
;
case "Numeric":
e.Item.Cells[cells].HorizontalAlign = HorizontalAlign.Right;
break
;
}
cells++;
}
}
catch

{

}
}

///
<summary>
/// Helper Functions Used to Various Validator Control

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
private
void AddValidatorControl(DataGridItemEventArgs e, int cells)
{
DataTable dt = ((DataView)this.DataSource).Table;

for
(int i = 0; i < dt.Columns.Count; i++)
{
string strCellName = this.NamingContainer.ID + "_" + this.ID + "_row" + e.Item.Cells.Count + "_ctr" + dt.Columns[i].Ordinal.ToString();

//Putting Required Field Validators For Colunms

if
(!dt.Columns[i].ReadOnly && !dt.Columns[i].AllowDBNull)
{
for (int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
e.Item.Cells[cells].Controls.Add(RequiredFieldValidatorControl(strCellName));
}

if
(e.Item.Cells[cells].Controls[ctl] is DropDownList)
{
((DropDownList)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
e.Item.Cells[cells].Controls.Add(RequiredFieldValidatorControl(strCellName));
}
}
}

//Putting The Range Validator To Handle Arthi OverFlow Error

switch
(dt.Columns[i].DataType.ToString())
{
case ("System.Decimal"):
for (int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
if (object.Equals(((TextBox)e.Item.Cells[cells].Controls[ctl]).ID, null))
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
e.Item.Cells[cells].Controls.Add(this.RangeValidatorControl(strCellName, ValidationDataType.Double, dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.MaxValue], dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.MinValue]));
}
}
break
;
case ("System.Int16"):
break;
case ("System.Int32"):
break;
case ("System.Int64"):
break;
}

//Adding Additional Required Field Validator Controls

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRequiredFieldValidator], null))
{
RequiredFieldValidator rfv = new RequiredFieldValidator();

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRequiredFieldValidatorErrorMessage], null))
{
rfv.ErrorMessage = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRequiredFieldValidatorErrorMessage].ToString();
}
else

{
rfv.ErrorMessage = REQUIREDERRORMESSAGE;
}

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRequiredFieldValidatorCssClass], null))
{
rfv.CssClass = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRequiredFieldValidatorCssClass].ToString();
}
else

{
rfv.CssClass = VALIDATORSTYLESHEET;
}

for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
else
if (e.Item.Cells[cells].Controls[ctl] is DropDownList)
{
((DropDownList)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
}

rfv.ControlToValidate = strCellName;

e.Item.Cells[cells].Controls.Add(rfv);
}
//Adding Additional Regular Expression Validator Controls

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidator], null))
{
RegularExpressionValidator rev = new RegularExpressionValidator();
if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorErrorMessage], null))
{
rev.ErrorMessage = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorErrorMessage].ToString();
}
else

{
rev.ErrorMessage = REGULARERRORMESSAGE;
}

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorCssClass], null))
{
rev.CssClass = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorCssClass].ToString();
}
else

{
rev.CssClass = VALIDATORSTYLESHEET;
}

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorExpression], null))
{
rev.ValidationExpression = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomRegularExpressionValidatorExpression].ToString();
}
else

{
throw new ArgumentNullException("Regular Expression Patern Not Set For Column " + dt.Columns[i].ColumnName);
}

for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
else
if (e.Item.Cells[cells].Controls[ctl] is DropDownList)
{
((DropDownList)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
}

rev.ControlToValidate = strCellName;

e.Item.Cells[cells].Controls.Add(rev);
}

//Adding Additional Custom Validator Controls

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidator], null))
{
CustomValidator cv = new CustomValidator();
if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorErrorMessage], null))
{
cv.ErrorMessage = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorErrorMessage].ToString();
}
else

{
cv.ErrorMessage = CUSTOMERRORMESSAGE;
}

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorCssClass], null))
{
cv.CssClass = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorCssClass].ToString();
}
else

{
cv.CssClass = VALIDATORSTYLESHEET;
}

if
(!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorClientValidationFunction], null))
{
cv.ClientValidationFunction = dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.CustomCustomValidatorClientValidationFunction].ToString();
}
else

{
throw new ArgumentNullException("Custom Validator Client Validation Function Not Set " + dt.Columns[i].ColumnName);
}

for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
else
if (e.Item.Cells[cells].Controls[ctl] is DropDownList)
{
((DropDownList)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
}

cv.ControlToValidate = strCellName;

e.Item.Cells[cells].Controls.Add(cv);
}
//Range Validator


//Compare Validator


cells++;
}
}
///
<summary>
/// Helper Function Used To Add Multiple Controls

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
private
void AddMultipleControls(DataGridItemEventArgs e, int cells)
{
DataTable dt = ((DataView)this.DataSource).Table;

for
(int i = 0; i < dt.Columns.Count; i++)
{
string strCellName = this.NamingContainer.ID + "_" + this.ID + "_row" + e.Item.Cells.Count + "_ctr" + dt.Columns[i].Ordinal.ToString();

//Putting The Range Validator To Handle Arthi OverFlow Error

switch
(dt.Columns[i].DataType.ToString())
{
case ("System.String"):
if (!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.ElipseButton], null))
{
TextBox textbox = new TextBox();
for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
if (object.Equals(((TextBox)e.Item.Cells[cells].Controls[ctl]).ID, null))
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
//Storing The Textbox Information In ElipseTextBox

textbox = ((TextBox)e.Item.Cells[cells].Controls[ctl]);
}
else
if (e.Item.Cells[cells].Controls[ctl] is HtmlInputButton && !object.Equals(textbox, null))
{
((HtmlInputButton)e.Item.Cells[cells].Controls[ctl]).Attributes.Add("onclick", this.NamingContainer.ID + this.ID + dt.Columns[i].ColumnName.Replace(" ", "_") + "(document.forms[0]." + textbox.ClientID + "," + (e.Item.ItemIndex + 1) + "," + cells + ")");
}
}
}
else
if (!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControl], null))
{
//
object
[] obj = (object[])dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControl];
//

string
strControlValue = string.Empty;
//

if
(e.Item.Cells[cells].Controls[0] is TextBox)
{
strControlValue = ((TextBox)e.Item.Cells[cells].Controls[0]).Text;
}
else
if (e.Item.Cells[cells].Controls[0] is Literal)
{
strControlValue = ((Literal)e.Item.Cells[cells].Controls[0]).Text;
}
//

string
[] spliter = strControlValue.Split(new char[1] { char.Parse(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControlDelimiter].ToString()) });
//

e.Item.Cells[cells].Controls.RemoveAt(0);
//

for
(int ctr = 0; ctr < obj.Length; ctr++)
{
Hashtable hashtable = (Hashtable)obj[ctr];

if
(hashtable[EMSDataGridExtendedProperties.MultipleControlDropDown] is DropDownList)
{
DropDownList dropdownlist;

if
(this.FullEditable)
{
//TODO: Having Problem In Memory Management Of Adding The Same Object To The Grid Control
dropdownlist = new DropDownList();
}
else

{
dropdownlist = (DropDownList)hashtable[EMSDataGridExtendedProperties.MultipleControlDropDown];
}

dropdownlist.CssClass = DROPDOWNSTYLE;
if
(object.Equals(dropdownlist.ID, null))
{
dropdownlist.ID = dt.Columns[i].ColumnName + "_" + ctr.ToString();
}
DataTable
datatable = (DataTable)hashtable[EMSDataGridExtendedProperties.MultipleControlDropDownDataTable];

dropdownlist.DataSource = datatable;
dropdownlist.DataTextField = hashtable[EMSDataGridExtendedProperties.MultipleControlDropDownDataTextField].ToString();
dropdownlist.DataValueField = hashtable[EMSDataGridExtendedProperties.MultipleControlDropDownDataValueField].ToString();
dropdownlist.DataBind();

dropdownlist.Items[0].Text = DROPDOWNDEFAULTTEXT;

if
(spliter.Length == obj.Length)
{
if (spliter[ctr].Length > 0)
{
dropdownlist.SelectedValue = spliter[ctr];
}
}

if
(this.FullEditable)
{
if (!object.Equals(dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly], null))
{
if (dt.Rows[e.Item.ItemIndex][dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()].GetType().ToString() == "System.Boolean")
{
bool blnFlag = (bool)dt.Rows[e.Item.ItemIndex][dt.Columns[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()];

if
(!blnFlag)
{
e.Item.Cells[cells].Controls.Add(dropdownlist);

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator], null))
{
RequiredFieldValidator rfv;

if
(this.FullEditable)
{
rfv = new RequiredFieldValidator();
}
else

{
rfv = (RequiredFieldValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator];
}

rfv.ErrorMessage = REQUIREDERRORMESSAGE + "<BR>"
rfv.CssClass = VALIDATORSTYLESHEET;
rfv.ControlToValidate = dropdownlist.ID;
rfv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rfv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator], null))
{
CompareValidator cv;

if
(this.FullEditable)
{
cv = new CompareValidator();
}
else

{
cv = (CompareValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator];
}

cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator], null))
{
CustomValidator cv;

if
(this.FullEditable)
{
cv = new CustomValidator();
}
else

{
cv = (CustomValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator];
}

cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator], null))
{
RangeValidator rv;

if
(this.FullEditable)
{
rv = new RangeValidator();
}
else

{
rv = (RangeValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator];
}

rv.CssClass = VALIDATORSTYLESHEET;
rv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator], null))
{
RegularExpressionValidator re;

if
(this.FullEditable)
{
re = new RegularExpressionValidator();
}
else

{
re = (RegularExpressionValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator];
}
re.CssClass = VALIDATORSTYLESHEET;
re.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(re);
}
}
else

{
e.Item.Cells[cells].Text = strControlValue;
}
}
}
else

{
e.Item.Cells[cells].Controls.Add(dropdownlist);

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator], null))
{
RequiredFieldValidator rfv;

if
(this.FullEditable)
{
rfv = new RequiredFieldValidator();
}
else

{
rfv = (RequiredFieldValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator];
}

rfv.ErrorMessage = REQUIREDERRORMESSAGE + "<BR>"
rfv.CssClass = VALIDATORSTYLESHEET;
rfv.ControlToValidate = dropdownlist.ID;
rfv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rfv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator], null))
{
CompareValidator cv;

if
(this.FullEditable)
{
cv = new CompareValidator();
}
else

{
cv = (CompareValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator];
}
cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator], null))
{
CustomValidator cv;

if
(this.FullEditable)
{
cv = new CustomValidator();
}
else

{
cv = (CustomValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator];
}
cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator], null))
{
RangeValidator rv;

if
(this.FullEditable)
{
rv = new RangeValidator();
}
else

{
rv = (RangeValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator];
}

//RangeValidator rv = (RangeValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator];

rv.CssClass = VALIDATORSTYLESHEET;
rv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator], null))
{
RegularExpressionValidator re;

if
(this.FullEditable)
{
re = new RegularExpressionValidator();
}
else

{
re = (RegularExpressionValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator];
}
re.CssClass = VALIDATORSTYLESHEET;
re.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(re);
}
}
}
else

{
e.Item.Cells[cells].Controls.Add(dropdownlist);

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator], null))
{
RequiredFieldValidator rfv = (RequiredFieldValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRequiredFieldValidator];
rfv.ErrorMessage = REQUIREDERRORMESSAGE + "<BR>"
rfv.CssClass = VALIDATORSTYLESHEET;
rfv.ControlToValidate = dropdownlist.ID;
rfv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rfv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator], null))
{
CompareValidator cv = (CompareValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCompareValidator];
cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator], null))
{
CustomValidator cv = (CustomValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlCustomValidator];
cv.CssClass = VALIDATORSTYLESHEET;
cv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(cv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator], null))
{
RangeValidator rv = (RangeValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRangeValidator];
rv.CssClass = VALIDATORSTYLESHEET;
rv.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(rv);
}

if
(!object.Equals(hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator], null))
{
RegularExpressionValidator re = (RegularExpressionValidator)hashtable[EMSDataGridExtendedProperties.MultipleControlRegularExpressionValidator];
re.CssClass = VALIDATORSTYLESHEET;
re.Display = ValidatorDisplay.Dynamic;
e.Item.Cells[cells].Controls.Add(re);
}
}
}
}
}
break
;
}
cells++;
}
}
///
<summary>
/// Helper Function Used To Set The Values For Editable Grid Items

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
///
<param name="row"></param>
///
<param name="dr"></param>
///
<param name="dc"></param>
///
<param name="columncount"></param>
private
void BindServerControl(DataGridItem e, int cells, int row, DataRow dr, DataColumnCollection dc, int columncount)
{
//
DataTable
dt = ((DataView)this.DataSource).Table;
//

DataColumn
[] dcPrimaryKey;
//

dcPrimaryKey = dt.PrimaryKey;
#region
Making The Whole Row As ReadOnly
if
(dcPrimaryKey.Length == 1)
{
if (!object.Equals(dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow], null))
{
//
if
(dr[dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow].ToString()].GetType().ToString() == "System.Boolean")
{
//
if
((bool)dr[dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow].ToString()])
{
//
if
(!Object.Equals(dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyStyle], null))
{
e.CssClass = dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyStyle].ToString();
}
else

{
e.CssClass = "CATDataGridReadOnlyItemStyle"
}
//

if
(e.Cells[0].Controls[0] is LinkButton)
{
e.Cells[0].Controls.RemoveAt(0);
}
//

if
(e.Cells[1].Controls[0] is LinkButton)
{
e.Cells[1].Controls.RemoveAt(0);
}
}
}
}
}
#endregion

//

for
(int i = 0; i < columncount; i++)
{
if (!dc[i].ReadOnly)
{
#region Setting The Control Values
//Putting The Range Validator To Handle Arthi OverFlow Error

switch
(dc[i].DataType.ToString())
{
#region Setting Drop Down Box Value with GUID DataType
case
("System.Guid"):
for (int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
if (e.Cells[cells].Controls[ctl] is DropDownList)
{
this.BindDropDown((DropDownList)e.Cells[cells].Controls[ctl], dr[i].ToString(), dc[i].ColumnName, dc[i].Caption, dc[i].ExtendedProperties);
if
(e.Cells[cells].Controls[0] is Literal)
{
e.Cells[cells].Controls.RemoveAt(0);
}

break
;
}
else
if (e.Cells[cells].Controls[ctl] is Literal)
{
e.Cells[cells].ID = this.NamingContainer.ClientID + "_" + this.ClientID + "_" + e.ItemIndex + "_" + cells + "_" + dr[i].ToString();
}
}
break
;
#endregion
#region
Setting TextBox Value with Decimal DataType
case
("System.Decimal"):
for (int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
if (e.Cells[cells].Controls[ctl] is TextBox)
{
((TextBox)e.Cells[cells].Controls[ctl]).Text = dr[i].ToString();
break
;
}
}
break
;
#endregion
case
("System.Int16"):
break;
case ("System.Int32"):
break;
case ("System.Int64"):
break;
#region Setting TextBox Value with DataTime DataType
case
("System.DateTime"):
if (!object.Equals(dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ConcurrencyState], null))
{
if (e.ItemType == ListItemType.EditItem)
{
if (object.Equals(this.ViewState[HIDDENCONCURRENCYSTATE], null))
{
if (!object.Equals(dr[i], DBNull.Value))
{
this.ViewState[HIDDENCONCURRENCYSTATE] = this.DateConvertorConcurrency((DateTime)dr[i]);
this
.ViewState["ItemIndex"] = e.ItemIndex;
}
}
else
if (this.ViewState[HIDDENCONCURRENCYSTATE].ToString().Trim().Length > 0 && (int)this.ViewState["ItemIndex"] != e.ItemIndex)
{
if (!object.Equals(dr[i], DBNull.Value))
{
this.ViewState[HIDDENCONCURRENCYSTATE] = this.DateConvertorConcurrency((DateTime)dr[i]);
this
.ViewState["ItemIndex"] = e.ItemIndex;
}
}
}
}
break
;
#endregion
}
#endregion
#region
Setting A Particular Column As ReadOnly In EnLine Edit
//

if
(!object.Equals(dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly], null))
{
Literal lit = new Literal();
//

if
(dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].GetType().ToString() == "System.Boolean")
{
for (int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
//
if
(e.Cells[cells].Controls[ctl] is TextBox)
{
//
if
((bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly])
{
lit.Text = ((TextBox)e.Cells[cells].Controls[ctl]).Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
//

if
(e.Cells[cells].Controls[ctl] is DropDownList)
{
//
if
((bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly])
{
lit.Text = ((DropDownList)e.Cells[cells].Controls[ctl]).SelectedItem.Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
}
}
//

else
if (dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()].GetType().ToString() == "System.Boolean")
{
//
for
(int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
//
if
(e.Cells[cells].Controls[ctl] is TextBox)
{
//
if
((bool)dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()])
{
lit.Text = ((TextBox)e.Cells[cells].Controls[ctl]).Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
//

if
(e.Cells[cells].Controls[ctl] is DropDownList)
{
//
if
((bool)dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()])
{
lit.Text = ((DropDownList)e.Cells[cells].Controls[ctl]).SelectedItem.Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
}
}
}
#endregion
}
cells++;
}
}

///
<summary>
/// Helper function Used To Make A Row or Column ReadOnly

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
///
<param name="row"></param>
///
<param name="dr"></param>
///
<param name="dc"></param>
///
<param name="columncount"></param>
private
void SetRowColumnReadOnly(DataGridItem e, int cells, int row, DataRow dr, DataColumnCollection dc, int columncount)
{
//
DataTable
dt = ((DataView)this.DataSource).Table;
//

DataColumn
[] dcPrimaryKey;
//

dcPrimaryKey = dt.PrimaryKey;
#region
Making The Whole Row As ReadOnly
if
(dcPrimaryKey.Length == 1)
{
if (!object.Equals(dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow], null))
{
//
if
(dr[dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow].ToString()].GetType().ToString() == "System.Boolean")
{
//
if
((bool)dr[dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyRow].ToString()])
{
//
if
(!Object.Equals(dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyStyle], null))
{
e.CssClass = dcPrimaryKey[0].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnlyStyle].ToString();
}
else

{
e.CssClass = "CATDataGridReadOnlyItemStyle"
}
//

foreach
(TableCell tc in e.Cells)
{
foreach (Control control in tc.Controls)
{
if (control is TextBox)
{
//
Literal
lit = new Literal();
lit.Text = ((TextBox)control).Text;
tc.Controls.Remove(control);
tc.Controls.Add(lit);
}
else
if (control is DropDownList)
{
//
Literal
lit = new Literal();
lit.Text = ((DropDownList)control).SelectedItem.Text;
tc.Controls.Remove(control);
tc.Controls.Add(lit);
}
else
if (control is CheckBox)
{
((CheckBox)control).Enabled = false;
}
}
}
}
}
}
}
#endregion

//

for
(int i = 0; i < columncount; i++)
{
if (!dc[i].ReadOnly)
{
#region Setting A Particular Column As ReadOnly In EnLine Edit
//

if
(!object.Equals(dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly], null))
{
if (dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].GetType().ToString() == "System.Boolean")
{
for (int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
//
if
(e.Cells[cells].Controls[ctl] is TextBox)
{
//
if
((bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly])
{
Literal lit = new Literal();
//                                                                                                                                                                                                                                                                                                                                                                                                                                                        

lit.Text = ((TextBox)e.Cells[cells].Controls[ctl]).Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
//

if
(e.Cells[cells].Controls[ctl] is DropDownList)
{
//
if
((bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly])
{
Literal lit = new Literal();
//

lit.Text = ((DropDownList)e.Cells[cells].Controls[ctl]).SelectedItem.Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
//

if
(e.Cells[cells].Controls[ctl] is CheckBox)
{
((CheckBox)e.Cells[cells].Controls[ctl]).Enabled = (bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly];
break
;
}
}
}
//

else
if (dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()].GetType().ToString() == "System.Boolean")
{
//
for
(int ctl = 0; ctl < e.Cells[cells].Controls.Count; ctl++)
{
//
if
(e.Cells[cells].Controls[ctl] is TextBox)
{
//
if
((bool)dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()])
{
Literal lit = new Literal();
//

lit.Text = ((TextBox)e.Cells[cells].Controls[ctl]).Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
//

if
(e.Cells[cells].Controls[ctl] is DropDownList)
{
//
if
((bool)dr[dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly].ToString()])
{
Literal lit = new Literal();
//

lit.Text = ((DropDownList)e.Cells[cells].Controls[ctl]).SelectedItem.Text;
e.Cells[cells].Controls.Add(lit);
e.Cells[cells].Controls.Remove(e.Cells[cells].Controls[ctl]);
}
break
;
}
if
(e.Cells[cells].Controls[ctl] is CheckBox)
{
((CheckBox)e.Cells[cells].Controls[ctl]).Enabled = (bool)dc[i].ExtendedProperties[EMSDataGridExtendedProperties.ReadOnly];
break
;
}
}
}
}
#endregion
}
cells++;
}
}

///
<summary>
/// Helper function Used To Set The Selected Value Of The Added DropDown Box

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
private
void SetDropDownSelectedValue(DataGridItemEventArgs e, int cells)
{
DataTable dt = ((DataView)this.DataSource).Table;
string
strLiteralText = null;
int
intRemove = -1;

for
(int i = 0; i < dt.Columns.Count; i++)
{
if (!dt.Columns[i].ReadOnly)
{
//Putting The Range Validator To Handle Arthi OverFlow Error
switch
(dt.Columns[i].DataType.ToString())
{
case ("System.Guid"):
for (int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is Literal)
{
strLiteralText = ((Literal)e.Item.Cells[cells].Controls[ctl]).Text;
intRemove = ctl;
}
if
(e.Item.Cells[cells].Controls[ctl] is DropDownList)
{
if (strLiteralText.Length > 0)
{
((DropDownList)e.Item.Cells[cells].Controls[ctl]).SelectedValue = strLiteralText;
}
}
}
if
(intRemove > -1)
{
e.Item.Cells[cells].Controls.RemoveAt(intRemove);
intRemove = -1;
}
break
;
}
}
cells++;
}
}
///
<summary>
/// Helper Function Used To Add Required Field Validator Control

///
</summary>
///
<param name="ID"></param>
///
<returns></returns>
private
RequiredFieldValidator RequiredFieldValidatorControl(string ID)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.CssClass = VALIDATORSTYLESHEET;
rfv.Display = ValidatorDisplay.Dynamic;
rfv.ControlToValidate = ID;

if
(!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.RequiredErrorMessage], null))
{
rfv.ErrorMessage = this.PropertyCollection[EMSDataGridExtendedProperties.RequiredErrorMessage].ToString();
}
else

{
rfv.ErrorMessage = REQUIREDERRORMESSAGE;
}

return
rfv;
}
///
<summary>
/// Helper Function Used Add The Range Validator Control

///
</summary>
///
<param name="ID"></param>
///
<param name="ValDataType"></param>
///
<param name="MaxValue"></param>
///
<param name="MinValue"></param>
///
<returns></returns>
private
RangeValidator RangeValidatorControl(string ID, ValidationDataType ValDataType, object MaxValue, object MinValue)
{
RangeValidator rv = new RangeValidator();
rv.CssClass = VALIDATORSTYLESHEET;
rv.Display = ValidatorDisplay.Dynamic;
rv.Type = ValDataType;
rv.ControlToValidate = ID;
if
(!Object.Equals(MaxValue, null))
{
rv.MaximumValue = MaxValue.ToString();
}
else

{
rv.MaximumValue = this.DecimalMaxValue;
}
if
(!Object.Equals(MinValue, null))
{
rv.MinimumValue = MinValue.ToString();
}
else

{
rv.MinimumValue = this.DecimalMinValue;
}

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.RequiredErrorMessage], null))
{
rv.ErrorMessage = PropertyCollection[EMSDataGridExtendedProperties.RequiredErrorMessage].ToString();
}
else

{
rv.ErrorMessage = RANGEERRORMESSAGE;
}

return
rv;
}
///
<summary>
/// Helper Function To Populate The Drop Down Box

///
</summary>
///
<param name="ddl"></param>
///
<param name="strDefaultData"></param>
///
<param name="columnname"></param>
///
<param name="columncaption"></param>
///
<param name="PropertyCollection"></param>
private
void BindDropDown(DropDownList ddl, string strDefaultData, string columnname, string columncaption, System.Data.PropertyCollection PropertyCollection)
{
//string strSelectedValue = string.Empty;

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.DataTable], null))
{
DataTable dt = (DataTable)PropertyCollection[EMSDataGridExtendedProperties.DataTable];

if
(!object.Equals(dt.Rows[0][0], DBNull.Value))
{
DataRow dr = dt.NewRow();
dr[0] = DBNull.Value;
dr[1] = DROPDOWNDEFAULTTEXT;
dt.Rows.InsertAt(dr, 0);
}

ddl.DataSource = dt;

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.DataValueField], null))
{
ddl.DataValueField = PropertyCollection[EMSDataGridExtendedProperties.DataValueField].ToString();
}
else

{
throw new Exception(this.NamingContainer.ID + " Following Drop Down List Text Field Not Set For DataTable " + dt.TableName + " Column " + columnname + " i.e. " + columncaption);
}

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.DataTextField], null))
{
ddl.DataTextField = PropertyCollection[EMSDataGridExtendedProperties.DataTextField].ToString();
}
else

{
throw new Exception(this.NamingContainer.ID + " Following Drop Down List Text Field Not Set For DataTable " + dt.TableName + " Column " + columnname + " i.e. " + columncaption);
}
ddl.DataBind();
ddl.CssClass = DROPDOWNSTYLE;
ddl.SelectedValue = strDefaultData;
}
else

{
throw new Exception(this.NamingContainer.ID + " Data Table Not Set For The Drop Down Box " + columnname + " i.e. " + columncaption);
}
}
///
<summary>
/// Reads The Data From The DataItem And updates the bounded datasource

///
</summary>
public
void EMSDataGridReadData()
{
//This function is used to update all the Rows from the DataGrid
this
.ReadDataGridData(this.EditItemIndex);
}
///
<summary>
/// Reads The Data From The DataItem And updates the bounded datasource

///
</summary>
///
<param name="row"></param>
private
void ReadDataGridData(int row)
{
object DBValue;
//Update The DataSource With Latest Information

DataTable
dt = ((DataView)this.DataSource).Table;
int
Cell, BaseCell;
int
Item;
if
(object.Equals(dt, null)) return;

if
(row == -1)
{
row = 0;
BaseCell = 1;
Cell = BaseCell;
Item = 0;
}
else

{
BaseCell = 2;
Cell = BaseCell;
Item = row;
}

//foreach(DataGridItem datagridItem in this.Items)

for
(; Item < this.Items.Count; Item++)
{
DataRow dr = dt.Rows[row];
row++;
for
(int col = 0; col < dt.Columns.Count; col++)
{
if (!dt.Columns[col].ReadOnly)
{
switch (dt.Columns[col].DataType.ToString())
{
case ("System.Guid"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is DropDownList)
{
DBValue = SetValidDBValue(((DropDownList)this.Items[Item].Cells[Cell].Controls[ctl]).SelectedValue);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Not Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
break
;
}
}
}
break
;
case ("System.String"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
string strData = null;
for
(int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);
}
else
if (this.Items[Item].Cells[Cell].Controls[ctl] is Literal)
{
DBValue = SetValidDBValue(((Literal)this.Items[Item].Cells[Cell].Controls[ctl]).Text);
}
else
if (this.Items[Item].Cells[Cell].Controls[ctl] is DropDownList)
{
DBValue = SetValidDBValue(((DropDownList)this.Items[Item].Cells[Cell].Controls[ctl]).SelectedValue);
}
else

{
DBValue = null;
}
if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
if (!object.Equals(dt.Columns[col].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControl], null))
{
if (!object.Equals(DBValue, null))
{
if (object.Equals(strData, null))
{
strData = DBValue.ToString();
}
else

{
strData = strData + dt.Columns[col].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControlDelimiter].ToString() + DBValue.ToString();
}
}
}
else

{
dr[col] = DBValue;
break
;
}
}
}
if
(!object.Equals(dt.Columns[col].ExtendedProperties[EMSDataGridExtendedProperties.MultipleControl], null))
{
dr[col] = strData;
}
}
break
;
case ("System.Boolean"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is CheckBox)
{
dr[col] = ((CheckBox)this.Items[Item].Cells[Cell].Controls[ctl]).Checked;
}
}
}
break
;
case ("System.Int64"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.Decimal"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.Double"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.Int32"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.Int16"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.Byte"):
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
break
;
case ("System.DateTime"):
if (!object.Equals(dt.Columns[col].ExtendedProperties[EMSDataGridExtendedProperties.ConcurrencyState], null))
{
if (!object.Equals(this.ViewState[HIDDENCONCURRENCYSTATE], null))
{
dr[col] = this.DateConvertorConcurrency(this.ViewState[HIDDENCONCURRENCYSTATE].ToString());
this
.ViewState[HIDDENCONCURRENCYSTATE] = null;
}
}
else

{
if (this.Items[Item].Cells[Cell].Controls.Count > 0)
{
for (int ctl = 0; ctl < this.Items[Item].Cells[Cell].Controls.Count; ctl++)
{
if (this.Items[Item].Cells[Cell].Controls[ctl] is TextBox)
{
DBValue = this.GetValidDate(this.GetValidValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text));
//DBValue = SetValidDBValue(((TextBox)this.Items[Item].Cells[Cell].Controls[ctl]).Text);

if
(!dt.Columns[col].AllowDBNull && object.Equals(DBValue, DBNull.Value))
{
throw new Exception("||" + dt.Columns[col].ColumnName + " Does Accept Null Values||");
}
else

{
dr[col] = DBValue;
}
}
}
}
}
break
;
}
}
//Incrementing The Cell

if
(this.EditItemIndex == -1)
{
if (Cell == dt.Columns.Count)
{
Cell = BaseCell;
}
else

{
Cell++;
}
}
else

{
Cell++;
}
}
if
(this.EditItemIndex != -1)
{
break;
}
}
}
///
<summary>
/// Adds The DataControl For The DataItem If The DataType Is DataTime

///
</summary>
///
<param name="e"></param>
///
<param name="cells"></param>
private
void AddDateControl(DataGridItemEventArgs e, int cells)
{
DataTable dt = ((DataView)this.DataSource).Table;

for
(int i = 0; i < dt.Columns.Count; i++)
{
string strCellName = this.NamingContainer.ID + "_" + this.ID + "_row" + e.Item.Cells.Count + "_ctr" + dt.Columns[i].Ordinal.ToString();

//Putting The Range Validator To Handle Arthi OverFlow Error

switch
(dt.Columns[i].DataType.ToString())
{
case ("System.DateTime"):
TextBox textbox = new TextBox();
for
(int ctl = 0; ctl < e.Item.Cells[cells].Controls.Count; ctl++)
{
if (e.Item.Cells[cells].Controls[ctl] is TextBox)
{
if (object.Equals(((TextBox)e.Item.Cells[cells].Controls[ctl]).ID, null))
{
((TextBox)e.Item.Cells[cells].Controls[ctl]).ID = strCellName;
}
//Storing The Textbox Information In ElipseTextBox

textbox = ((TextBox)e.Item.Cells[cells].Controls[ctl]);

if
(!object.Equals(textbox, null))
{
e.Item.Cells[cells].VerticalAlign = VerticalAlign.Top;
Literal
literal = new Literal();
literal.Text = "&nbsp;"
e.Item.Cells[cells].Controls.Add(literal);
ImageButton
ibtnCalendarStartDate = new ImageButton();
ibtnCalendarStartDate.ImageUrl = this.ResolveUrl(System.Configuration.ConfigurationSettings.AppSettings["CalenderImage"]);
ibtnCalendarStartDate.Attributes.Add("onclick", "getCalendar(document.forms[0].item(\"" + textbox.ClientID + "\"), '" + this.ResolveUrl(System.Configuration.ConfigurationSettings.AppSettings["CalenderControl"]) + "'); return false;");
e.Item.Cells[cells].Controls.Add(ibtnCalendarStartDate);
}
}
else
if (e.Item.Cells[cells].Controls[ctl] is HtmlInputButton && !object.Equals(textbox, null))
{
((HtmlInputButton)e.Item.Cells[cells].Controls[ctl]).Attributes.Add("onclick", this.NamingContainer.ID + this.ID + dt.Columns[i].ColumnName + "(document.forms[0]." + textbox.ClientID + "," + (e.Item.ItemIndex + 1) + "," + cells + ")");
}


}
break
;
}
cells++;
}
}
///
<summary>
/// Adds The Functionality for Each DataItem To Maintain The checkbox state across pages

///
</summary>
///
<param name="e"></param>
private
void AddCheckBoxState(DataGridItemEventArgs e)
{
int intRowCount = 0;
int
intCurrentPageRowCount = 0;
string
strCheckBoxState = string.Empty;
string
strCheckBoxStateCount = string.Empty;
HtmlInputHidden
hidCheckBoxState = new HtmlInputHidden();
//                                                

//This Part of Code Is Used For Mainting Checkbox State Across Pages                                    

if
(this.blnCheckBoxState)
{
if (!object.Equals(this.ViewState[this.strHiddenCheckBoxState], null))
{
//Creating The Instance Of The DataSet
this
.dsCheckBoxState = new DataSet();
//Creating The Instance of StringReader Class

StringReader
sr = new StringReader(this.ViewState[this.strHiddenCheckBoxState].ToString());
//Loading The DataSet From StringReader Class

this
.dsCheckBoxState.ReadXml(sr);
}
//

switch
(e.Item.ItemType)
{
case ListItemType.Footer:
break;
case ListItemType.Header:
//this.strHiddenCheckBoxState = e.Item.Cells[this.intCheckBoxColumn].Controls[0].ClientID.Replace("__", ":_");
CheckBox
chkHeader = (CheckBox)e.Item.Cells[this.intCheckBoxColumn].Controls[0];
//

//chkHeader.ID = this.ID + e.Item.ItemIndex + e.Item.Cells[this.intCheckBoxColumn];

//

chkHeader.Attributes.Add("onclick", "EMSGridCheckAll(document.all." + this.ClientID + ", document.forms[0]." + chkHeader.ClientID + ");EMSGridCheckboxState(document.all." + this.ClientID + ", " + this.CurrentPageIndex + ", '" + this.strHiddenCheckBoxState + "', '" + this.strNoOfRecordsCheckBoxState + "', '" + this.strCheckBoxStateCount + "', document.forms[0].item(\"" + chkHeader.ClientID + "\")," + this.PageSize + ",'" + this.strHiddenPreviousPage + "');");
//

strHeaderCheckBoxId = chkHeader.ClientID;

if
(!this.blnClearGridStatus)
{
//
//Make The Previous Pages Checkbox Checked If Records Exists For Them

if
(!object.Equals(this.dsCheckBoxState, null))
{
//
if
(this.dsCheckBoxState.Tables.Count == 1)
{
//
if
(this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
DataRow[] dr = this.dsCheckBoxState.Tables[0].Select("PageNumber = " + this.CurrentPageIndex);
//                                        

if
((dr.Length) == this.PageSize)
{
chkHeader.Checked = true;
}
else

{
chkHeader.Checked = false;
}
}
}
}
//

if
(!object.Equals(HttpContext.Current.Request[this.strNoOfRecordsCheckBoxState], null))
{
if (!object.Equals(this.dsCheckBoxState, null))
{
if (this.dsCheckBoxState.Tables.Count > 0)
{
if (this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
//Filtering The DataTable Based on DataRows
DataRow
[] dr = dsCheckBoxState.Tables[0].Select("PageNumber" + "='" + this.CurrentPageIndex + "'");
//                                                                                                                                                                                                                                                                                                                                                                                                                                                        

intCurrentPageRowCount = dr.Length;
//

strCheckBoxState = intCurrentPageRowCount.ToString();
}
}
}
}
//

if
(!object.Equals(this.dsCheckBoxState, null))
{
if (!object.Equals(HttpContext.Current.Request[this.strCheckBoxStateCount], null))
{
if (this.dsCheckBoxState.Tables.Count > 0)
{
if (this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
//
intRowCount = this.dsCheckBoxState.Tables[0].Rows.Count - intCurrentPageRowCount;
//

strCheckBoxStateCount = intRowCount.ToString();
}
}
}
}
}
//Adding The Hidden Control To The Page

HtmlInputHidden
hid = new HtmlInputHidden();
hid.ID = HIDDENCHECKSTATE;
//

this
.Controls.Add(hid);
//Adding The Hidden Control To The Page

hidCheckBoxState.ID = HIDDENNORECORDSCHECKBOXSTATE;
hidCheckBoxState.Value = strCheckBoxState;
//

this
.Controls.Add(hidCheckBoxState);
//Adding the Hidden Control to The page

HtmlInputHidden
hidCheckBoxStateCount = new HtmlInputHidden();
hidCheckBoxStateCount.ID = HIDDENCHECKBOXSTATECOUNT;
hidCheckBoxStateCount.Value = strCheckBoxStateCount;
//

this
.Controls.Add(hidCheckBoxStateCount);
//

//this.Controls.Add(hidCheckBoxState);

HtmlInputHidden
hidPreviousPage = new HtmlInputHidden();
hidPreviousPage.ID = HIDDENPREVIOUSPAGE;
//

this
.Controls.Add(hidPreviousPage);
break
;
case ListItemType.AlternatingItem:
goto case ListItemType.Item;
case ListItemType.Item:
if (e.Item.Cells[this.intCheckBoxColumn].Controls[0] is CheckBox)
{
//
CheckBox
chk = (CheckBox)e.Item.Cells[this.intCheckBoxColumn].Controls[0];
//

chk.Enabled = true;
chk.Checked = false;
chk.ID = this.ID + e.Item.ItemIndex + this.intCheckBoxColumn;

if
(!this.blnClearGridStatus)
{
if (!object.Equals(HttpContext.Current.Request[this.strNoOfRecordsCheckBoxState], null))
{
if (!object.Equals(this.dsCheckBoxState, null))
{
if (this.dsCheckBoxState.Tables.Count > 0)
{
if (this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
//Filtering The DataTable Based on DataRows
DataRow
[] dr = dsCheckBoxState.Tables[0].Select("PageNumber" + "='" + this.CurrentPageIndex + "'");
//                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

intCurrentPageRowCount = dr.Length;
//

hidCheckBoxState.Value = intCurrentPageRowCount.ToString();
}
else

{
hidCheckBoxState.Value = string.Empty;
}
}
else

{
hidCheckBoxState.Value = string.Empty;
}
}
else

{
hidCheckBoxState.Value = string.Empty;
}
}

//Make The Previous Pages Checkbox Checked If Records Exists For Them

if
(!object.Equals(this.dsCheckBoxState, null))
{
//
if
(this.dsCheckBoxState.Tables.Count == 1)
{
//
if
(this.dsCheckBoxState.Tables[0].Rows.Count > 0)
{
DataRow[] dr = this.dsCheckBoxState.Tables[0].Select("Id ='" + e.Item.Attributes["ID"] + "'");
//                                            

if
(dr.Length == 1)
{
chk.Checked = true;
}
else

{
chk.Checked = false;
}
}
}
}
}
//                                                                                                                                                                                                    

chk.Attributes.Add("onclick", "EMSGridCheckboxState(document.all." + this.ClientID + ", " + this.CurrentPageIndex + ", '" + this.strHiddenCheckBoxState + "', '" + this.strNoOfRecordsCheckBoxState + "', '" + this.strCheckBoxStateCount + "', document.forms[0].item(\"" + this.strHeaderCheckBoxId + "\"), " + this.PageSize + ",'" + this.strHiddenPreviousPage + "');");
}
break
;
}
}
}
///
<summary>
/// Helper Function Adds The Client Side Functionality For Checkbox State

///
</summary>
private
void AddClientSideScript()
{
StringBuilder sbCheckAll = new StringBuilder();
sbCheckAll.Append("<script>");
sbCheckAll.Append("function EMSGridCheckAll(EmsGridId, HeaderCheckBox)");
sbCheckAll.Append("{");
sbCheckAll.Append("for(var row = 1; row < EmsGridId.rows.length; row++)");
sbCheckAll.Append("{");
sbCheckAll.Append("for(var col=0; col < EmsGridId.rows[row].cells.length; col++)");
sbCheckAll.Append("{");
sbCheckAll.Append("for(cells = 0; cells < EmsGridId.rows[row].cells(col).children.length; cells++)");
sbCheckAll.Append("{");
sbCheckAll.Append("if(EmsGridId.rows[row].cells(col).children[cells].type == \"checkbox\")");
sbCheckAll.Append("{");
sbCheckAll.Append("EmsGridId.rows[row].cells(col).children[cells].checked = HeaderCheckBox.checked"); ;
sbCheckAll.Append("}");
sbCheckAll.Append("break;");
sbCheckAll.Append("}");
sbCheckAll.Append("}");
sbCheckAll.Append("}");
sbCheckAll.Append("}");
sbCheckAll.Append("</script>");

StringBuilder
sbCheckBoxState = new StringBuilder();

sbCheckBoxState.Append("<script>");
//Adding The Function Attribute

sbCheckBoxState.Append("function EMSGridCheckboxState(EmsGridId, CurrentPageIndex, hidCheckBoxState, hidNoOfRecordsCheckBoxState, hidCheckRecordsCount, HeaderCheckBox, PageSize, PreviousPage)");
//Opening The function Braces

sbCheckBoxState.Append("{");
//Validating If The DataGrid Exisits

sbCheckBoxState.Append("if(EmsGridId == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid DataGrid Name');");
sbCheckBoxState.Append("return");
sbCheckBoxState.Append("}");
//Validating If The CurrentPageIndex Exisits

sbCheckBoxState.Append("if(CurrentPageIndex == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid Page Index');");
sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
//Converting hidCheckBoxState To An Object

sbCheckBoxState.Append("hidCheckBoxState = eval('document.forms[0].item(\"' + hidCheckBoxState +  '\")');");
//Converting hidNoOfRecordsCheckBoxState To An Object

sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState = eval('document.forms[0].item(\"' + hidNoOfRecordsCheckBoxState +  '\")');");
//PreviousPage

sbCheckBoxState.Append("PreviousPage = eval('document.forms[0].item(\"' + PreviousPage +  '\")');");
//

sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState.value = 0;");
//

sbCheckBoxState.Append("hidCheckRecordsCount = eval('document.forms[0].item(\"' + hidCheckRecordsCount +  '\")');");
//Validating if the converted hidCheckBoxState is an object

sbCheckBoxState.Append("if(hidCheckBoxState == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid Check Box State Control');");
sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
//Validating if the converted hidNoOfRecordsCheckBoxState is an object

sbCheckBoxState.Append("if(hidNoOfRecordsCheckBoxState == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid No Of Records Check Box State Control');");
sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
//Validating if the converted hidNoOfRecordsCheckBoxState is an object

sbCheckBoxState.Append("if(hidCheckRecordsCount == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid Check Records Count Control');");
sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
//Validating if the PreviousPage Control Exists

sbCheckBoxState.Append("if(PreviousPage == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("alert('Invalid Previous Page Control');");
sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
//Validating if the converted hidCheckBoxState's value is null

sbCheckBoxState.Append("if(hidCheckBoxState.value == \"\")");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("var data = CurrentPageIndex;");
sbCheckBoxState.Append("var pkdata;");
sbCheckBoxState.Append("for(var row = 1; row < EmsGridId.rows.length; row++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("for(var col=0; col < EmsGridId.rows[row].cells.length; col++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("for(cells = 0; cells < EmsGridId.rows[row].cells(col).children.length; cells++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].cells(col).children[cells].type == \"checkbox\")");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].cells(col).children[cells].checked)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(pkdata == null)");
sbCheckBoxState.Append("{");
//sbCheckBoxState.Append("alert(EmsGridId.rows[row].id.length);");

sbCheckBoxState.Append("if(EmsGridId.rows[row].id.length > 0)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pkdata = EmsGridId.rows[row].id;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
//sbCheckBoxState.Append("alert(EmsGridId.rows[row].id.length);");

sbCheckBoxState.Append("if(EmsGridId.rows[row].id.length > 0)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pkdata = pkdata + \"^\" + EmsGridId.rows[row].id;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("break;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("if(pkdata == null)");
sbCheckBoxState.Append("{");
//

sbCheckBoxState.Append("PreviousPage.value = CurrentPageIndex;");
//

sbCheckBoxState.Append("return;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
//

sbCheckBoxState.Append("PreviousPage.value = CurrentPageIndex;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("hidCheckBoxState.value = data +\"~\"+ pkdata;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pagespliter = hidCheckBoxState.value.split(\"|\");");
sbCheckBoxState.Append("var data;");
sbCheckBoxState.Append("for(var page = 0;   page++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pageIndex   = pagespliter[page].split(\"~\");");
sbCheckBoxState.Append("if(pageIndex[0] == CurrentPageIndex)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("for(var row = 1; row < EmsGridId.rows.length; row++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("for(var col=0; col < EmsGridId.rows[row].cells.length; col++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("for(cells = 0; cells < EmsGridId.rows[row].cells(col).children.length; cells++)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].cells(col).children[cells].type == \"checkbox\")");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].cells(col).children[cells].checked)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(data == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].id != \"\")");
sbCheckBoxState.Append("{");
//sbCheckBoxState.Append("alert(EmsGridId.rows[row].id.length);");

sbCheckBoxState.Append("if(EmsGridId.rows[row].id.length > 0)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("data = EmsGridId.rows[row].id;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(EmsGridId.rows[row].id != \"\")");
sbCheckBoxState.Append("{");
//sbCheckBoxState.Append("alert(EmsGridId.rows[row].id.length);");

sbCheckBoxState.Append("if(EmsGridId.rows[row].id.length > 0)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("data = data + \"^\" + EmsGridId.rows[row].id;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("break;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("if(data == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pagespliter[page] = \"\"");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("pageIndex[1] = data;");
sbCheckBoxState.Append("pagespliter[page] = pageIndex.join(\"~\");");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("break;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("hidCheckBoxState.value = pagespliter.join(\"|\");");
//

sbCheckBoxState.Append("PreviousPage.value = CurrentPageIndex;");
sbCheckBoxState.Append("}");
//Adding The Number Of Rows Checked Across EMS

sbCheckBoxState.Append("var noofrows = hidCheckBoxState.value;");
sbCheckBoxState.Append("var noofrows = noofrows.split(\"~\");");
sbCheckBoxState.Append("if(noofrows.length == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState.value = 0;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("if(noofrows.length == 2)");
sbCheckBoxState.Append("{");
//sbCheckBoxState.Append("alert(noofrows[1]);");

sbCheckBoxState.Append("noofrows[1] = noofrows[1].split(\"^\");");
sbCheckBoxState.Append("if(noofrows[1].length == null)");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState.value = 0;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState.value = noofrows[1].length;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("hidNoOfRecordsCheckBoxState.value = 0;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("}");
//sbCheckBoxState.Append("if(parseInt(hidNoOfRecordsCheckBoxState.value) == 20)");

//sbCheckBoxState.Append("{");

//            sbCheckBoxState.Append("PageSize = PageSize + 1");

//sbCheckBoxState.Append("}");

//sbCheckBoxState.Append("alert(PageSize); alert(hidNoOfRecordsCheckBoxState.value);alert(EmsGridId.rows.length);");

sbCheckBoxState.Append("if((PageSize) == parseInt(hidNoOfRecordsCheckBoxState.value))");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("HeaderCheckBox.checked = true;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else if((EmsGridId.rows.length - 3) == parseInt(hidNoOfRecordsCheckBoxState.value))");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("HeaderCheckBox.checked = true;");
sbCheckBoxState.Append("}");
sbCheckBoxState.Append("else");
sbCheckBoxState.Append("{");
sbCheckBoxState.Append("HeaderCheckBox.checked = false;");
sbCheckBoxState.Append("}");
//sbCheckBoxState.Append("alert('Current Records =' + hidNoOfRecordsCheckBoxState.value);");

//sbCheckBoxState.Append("alert('Total Records = ' + hidCheckRecordsCount.value);");

//Closing The function Braces

//sbCheckBoxState.Append("alert(PreviousPage.value);");

//sbCheckBoxState.Append("alert('Hello');");

sbCheckBoxState.Append("}");
sbCheckBoxState.Append("</script>");
this
.Page.RegisterClientScriptBlock("sbCheckAll", sbCheckAll.ToString());
this
.Page.RegisterClientScriptBlock("sbCheckBoxState", sbCheckBoxState.ToString());
}

#endregion
}
///
<summary>
/// Implementing the DataGrid Template Class

///
</summary>
public
class DataGridTemplate : ITemplate
{
#region Member Variable
///
<summary>
/// ListItemType Variable Declaration

///
</summary>
ListItemType
listitemtype;
///
<summary>
/// columnnumber Variable Declaration

///
</summary>
int
columnnumber;
///
<summary>
/// columnname Variable Declaration

///
</summary>
string
columnname;
///
<summary>
/// columncaption Variable Declaration

///
</summary>
string
columncaption;
///
<summary>
/// columntype Variable Declaration

///
</summary>
string
columntype;
///
<summary>
/// columnmaxlength Variable Declaration

///
</summary>
int
columnmaxlength;
///
<summary>
/// allowsort Variable Declaration

///
</summary>
bool
allowsort;
///
<summary>
/// headercssclass Variable Declaration

///
</summary>
string
headercssclass;
///
<summary>
/// blnFullEditable Variable Declaration

///
</summary>
bool
blnFullEditable;
///
<summary>
/// blnReadOnly Variable Declaration

///
</summary>
bool
blnReadOnly;
///
<summary>
/// blnAllowDBNull Variable Declaration

///
</summary>
bool
blnAllowDBNull;
///
<summary>
/// blnEnhanceEdit Variable Declaration

///
</summary>
bool
blnEnhanceEdit;
///
<summary>
///  cellname Variable Declaration

///
</summary>
string
cellname;
///
<summary>
/// guid Varaible Declaration

///
</summary>
string
guid;
///
<summary>
/// PropertyCollection Variable Declaration

///
</summary>
System.Data.PropertyCollection PropertyCollection;
///
<summary>
/// RequiredFieldValidator style sheet declaration

///
</summary>
const
string VALIDATORSTYLESHEET = "RequiredFieldValidator"
///
<summary>
/// RangeValidator Error Message

///
</summary>
const
string RANGEERRORMESSAGE = "<BR><BLINK>||Invalid Data||</BLINK>"
///
<summary>
/// Required Field Error Message

///
</summary>
const
string REQUIREDERRORMESSAGE = "<BR><BLINK>||Required||</BLINK>"
///
<summary>
/// DropDown List Default Value

///
</summary>
const
string DROPDOWNDEFAULTTEXT = "||------SELECT------||"
///
<summary>
/// ReadOnly TextBox Style

///
</summary>
const
string READONLYTEXTBOXSTYLE = "ReadOnlyTextBoxStyle"
///
<summary>
/// Range Validator For Decimal field Max Value

///
</summary>
string
DecimalMaxValue = System.Configuration.ConfigurationSettings.AppSettings["DecimalMaxValue"];
///
<summary>
/// Range Validator For Decimal field Min Value

///
</summary>
string
DecimalMinValue = System.Configuration.ConfigurationSettings.AppSettings["DecimalMinValue"];
///
<summary>
/// CheckBoxState Variable Declaration

///
</summary>
bool
blnCheckBoxState;
///
<summary>
/// CheckBox Column Variable Declaration

///
</summary>
int
intCheckBoxColumn;
#endregion
#region
Public Method Of This Class
///
<summary>
/// contractor

///
</summary>
///
<param name="listItemType">The Type Of Item To Be Added</param>
///
<param name="columnName">Name Of The Column</param>
///
<param name="columnCaption">Column Heading</param>
///
<param name="columnNumber">Column Number</param>
///
<param name="columnType">DataType Of The Column</param>
///
<param name="allowSort">If Sorting Is Enabled</param>
///
<param name="headerCssClass">Style Sheet Class</param>
///
<param name="blnFullEditable">If Fully Editable</param>
///
<param name="blnReadOnly"></param>
///
<param name="PropertyCollection"></param>
///
<param name="AllowDBNull"></param>
///
<param name="blnEnhanceEdit"></param>
///
<param name="strcellname"></param>
///
<param name="columnmaxlength"></param>
///
<param name="blnCheckBoxState"></param>
///
<param name="intCheckBoxColumn"></param>
public
DataGridTemplate(ListItemType listItemType, string columnName, string columnCaption, int columnNumber, string columnType, bool allowSort, string headerCssClass, bool blnFullEditable, bool blnReadOnly, System.Data.PropertyCollection PropertyCollection, bool AllowDBNull, bool blnEnhanceEdit, string strcellname, int columnmaxlength, bool blnCheckBoxState, int intCheckBoxColumn)
{
//set the list item type
this
.listitemtype = listItemType;
//set the column number

this
.columnnumber = columnNumber;
//set the column name

this
.columnname = columnName;
//set the column caption

this
.columncaption = columnCaption;
//set the column type

this
.columntype = columnType;
//set the sort property

this
.allowsort = allowSort;
//set the header css class

this
.headercssclass = headerCssClass;
//set the FullEditable

this
.blnFullEditable = blnFullEditable;
//Used Is A Column Is ReadOnly

this
.blnReadOnly = blnReadOnly;
//Any Other Specific Data Column Collection

this
.PropertyCollection = PropertyCollection;
//Puts A Required Field Validator Control

this
.blnAllowDBNull = AllowDBNull;
//Puts The Appropriate Validator Controls

this
.blnEnhanceEdit = blnEnhanceEdit;
//Giving a unique name to a control

this
.cellname = strcellname;
//Maxlength Of The Column

this
.columnmaxlength = columnmaxlength;
//CheckBoxState

this
.blnCheckBoxState = blnCheckBoxState;
this
.intCheckBoxColumn = intCheckBoxColumn;
}
///
<summary>
/// implement the InstantiateIn method

///
</summary>
///
<param name="container"></param>
public
void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
//for listitem type, set the template style

#region
Setting Template Style
switch
(listitemtype)
{
//set the header style
case
ListItemType.Header:
if (this.blnCheckBoxState)
{
switch (columntype)
{
case "System.Boolean":
if (this.blnCheckBoxState)
{
CheckBox chkHeader = new CheckBox();
container.Controls.Add(chkHeader);
}
else

{
if (!allowsort)
{
lc.Text = "<B>" + columncaption + "</B>"
container.Controls.Add(lc);
}
else

{
LinkButton linkButton = new LinkButton();
linkButton.Text = columncaption;
linkButton.CommandName = "sort"
linkButton.CommandArgument = columnname;
linkButton.CssClass = headercssclass;
container.Controls.Add(linkButton);
//TableCell x = new TableCell();
}
}
break
;
default:
if (!allowsort)
{
lc.Text = "<B>" + columncaption + "</B>"
container.Controls.Add(lc);
}
else

{
LinkButton linkButton = new LinkButton();
linkButton.Text = columncaption;
linkButton.CommandName = "sort"
linkButton.CommandArgument = columnname;
linkButton.CssClass = headercssclass;
container.Controls.Add(linkButton);
//TableCell x = new TableCell();
}
break
;
}
}
else

{
if (!allowsort)
{
if (!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CustomColumnHeading], null))
{
lc.Text = "||<B>" + PropertyCollection[EMSDataGridExtendedProperties.CustomColumnHeading].ToString() + "</B>||"
}
else

{
lc.Text = "<B>" + columncaption + "</B>"
}
container.Controls.Add(lc);
}
else

{
LinkButton linkButton = new LinkButton();

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CustomColumnHeading], null))
{
linkButton.Text = "||<B>" + PropertyCollection[EMSDataGridExtendedProperties.CustomColumnHeading].ToString() + "</B>||"
}
else

{
linkButton.Text = "<B>" + columncaption + "</B>"
}

linkButton.CommandName = "sort"
linkButton.CommandArgument = columnname;
linkButton.CssClass = headercssclass;
container.Controls.Add(linkButton);
//TableCell x = new TableCell();
}
}
break
;
//set the item style
case
ListItemType.Item:
if (this.blnFullEditable && !this.blnReadOnly)
{
#region FullyEditable
//check the column type and set the control based on the datatype

switch
(columntype)
{
case "System.Guid": //UniqueIdentifier
//Bind Data
lc.DataBinding += new EventHandler(lc_SelectedDropDown);
container.Controls.Add(lc);
DropDownList
dp = new DropDownList();
this
.BindDropDown(dp);
dp.SelectedValue = lc.Text;
//dp.PreRender += new EventHandler(ddl_SelectedDropDown);

container.Controls.Add(dp);
break
;
case "System.String": //varchar
TextBox tb = new TextBox();
//tb.ID = this.cellname;

if
(this.columnmaxlength > 0)
{
tb.MaxLength = this.columnmaxlength;
}
tb.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}

container.Controls.Add(tb);
//Adding The Elipse Button If Required

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.ElipseButton], null))
{
HtmlInputButton elipseButton = new HtmlInputButton("Button");
elipseButton.Value = "..."
elipseButton.Attributes.Add("Style", "CustomButtonStyle");
elipseButton.Attributes.Add("title", "||Click Here To Open Popup||");
container.Controls.Add(elipseButton);
}
break
;
case "System.Boolean": //Bit
CheckBox cb = new CheckBox();
cb.DataBinding += new EventHandler(cb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
cb.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
cb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(cb);
break
;
case "System.Int64": //BigInt
TextBox tb1 = new TextBox();
tb1.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb1.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb1.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb1);
break
;
case "System.Decimal": //Decimal, Money, Numeric, SmallMoney
TextBox tb2 = new TextBox();
tb2.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb2.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb2.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
//Adding The TextBox

container.Controls.Add(tb2);
break
;
case "System.Double": //Float
TextBox tb3 = new TextBox();
tb3.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb3.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb3.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb3);
break
;
case "System.Int32": //Int
TextBox tb4 = new TextBox();
//tb4.ID = this.cellname;

tb4.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb4.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb4.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb4);
break
;
case "System.Int16": //smallInt
TextBox tb5 = new TextBox();
tb5.DataBinding += new EventHandler(tb_DataBinding);

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb5.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb5.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb5);
break
;
case "System.Byte": //tinyInt
TextBox tb6 = new TextBox();
tb6.DataBinding += new EventHandler(tb_DataBinding);
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb6.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb6.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb6);
break
;
case "System.DateTime": //DateTime
TextBox tb7 = new TextBox();
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb7.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
else

{
tb7.Width = 100;
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb7.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
else

{
tb7.CssClass = READONLYTEXTBOXSTYLE;
tb7.ReadOnly = true;
}
tb7.DataBinding += new EventHandler(tb7_DataBinding);
container.Controls.Add(tb7);
break
;
}
#endregion
}
else

{
#region NonEditable
switch
(columntype)
{
case "System.Boolean":
CheckBox cb = new CheckBox();
cb.DataBinding += new EventHandler(cb_DataBinding);
cb.Enabled = false;
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
cb.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
cb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(cb);
break
;
case "System.Guid":
if (!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataTable], null))
{
lc.DataBinding += new EventHandler(lc_SearchDataBinding);
}
else

{
lc.DataBinding += new EventHandler(lc_DataBinding);
}
container.Controls.Add(lc);
break
;
default:
lc.DataBinding += new EventHandler(lc_DataBinding);
container.Controls.Add(lc);
break
;
}
#endregion
}
break
;
//set the edit item style
case
ListItemType.EditItem:
//Validates if the  DB Constraints Need To Be Apply
if
(this.blnEnhanceEdit && !this.blnReadOnly)
{
#region Inline Edit Enhanced
//check the column type and set the control based on the datatype

switch
(columntype)
{
case "System.Guid": //UniqueIdentifier
if (!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataTable], null))
{
//Bind Data
lc.DataBinding += new EventHandler(lc_SelectedDropDown);
container.Controls.Add(lc);
DropDownList
dp = new DropDownList();
container.Controls.Add(dp);
}
break
;
case "System.String": //varchar
TextBox tb = new TextBox();
tb.MaxLength = this.columnmaxlength;
tb.DataBinding += new EventHandler(tb_DataBinding);

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb);
//Adding The Elipse Button If Required

if
(!object.Equals(PropertyCollection[EMSDataGridExtendedProperties.ElipseButton], null))
{
HtmlInputButton elipseButton = new HtmlInputButton("Button");
elipseButton.Value = "..."
elipseButton.Attributes.Add("Style", "CustomButtonStyle");
elipseButton.Attributes.Add("title", "||Click Here To Open Popup||");
container.Controls.Add(elipseButton);
}
break
;
case "System.Boolean": //Bit
CheckBox cb = new CheckBox();
cb.DataBinding += new EventHandler(cb_DataBinding);
//cb.ID = this.cellname;

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
cb.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
cb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(cb);
break
;
case "System.Int64": //BigInt
TextBox tb1 = new TextBox();
//tb1.ID = this.cellname;

tb1.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb1.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb1.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb1);
break
;
case "System.Decimal": //Decimal, Money, Numeric, SmallMoney
TextBox tb2 = new TextBox();
tb2.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb2.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb2.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb2);
break
;
case "System.Double": //Float
TextBox tb3 = new TextBox();
tb3.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb3.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb3.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb3);
break
;
case "System.Int32": //Int
TextBox tb4 = new TextBox();
tb4.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb4.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb4.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb4);
break
;
case "System.Int16": //smallInt
TextBox tb5 = new TextBox();
tb5.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb5.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb5.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb5);
break
;
case "System.Byte": //tinyInt
TextBox tb6 = new TextBox();
tb6.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb6.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb6.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
container.Controls.Add(tb6);
break
;
case "System.DateTime": //DateTime
TextBox tb7 = new TextBox();
tb7.DataBinding += new EventHandler(tb_DataBinding);
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.Width], null))
{
tb7.Width = (int)PropertyCollection[EMSDataGridExtendedProperties.Width];
}
else

{
tb7.Width = 100;
}
if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.CssClass], null))
{
tb7.CssClass = PropertyCollection[EMSDataGridExtendedProperties.CssClass].ToString();
}
else

{
tb7.CssClass = READONLYTEXTBOXSTYLE;
tb7.ReadOnly = true;
}

container.Controls.Add(tb7);
break
;
}
#endregion
}
else

{
#region Inline Edit
//check the column type and set the control based on the datatype

switch
(columntype)
{
case "System.Guid": //UniqueIdentifier
DropDownList dp = new DropDownList();
//Bind Data

container.Controls.Add(dp);
break
;
case "System.String": //varchar
TextBox tb = new TextBox();
tb.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb);
break
;
case "System.Boolean": //Bit
CheckBox cb = new CheckBox();
cb.DataBinding += new EventHandler(cb_DataBinding);
container.Controls.Add(cb);
break
;
case "System.Int64": //BigInt
TextBox tb1 = new TextBox();
tb1.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb1);
break
;
case "System.Decimal": //Decimal, Money, Numeric, SmallMoney
TextBox tb2 = new TextBox();
tb2.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb2);
break
;
case "System.Double": //Float
TextBox tb3 = new TextBox();
tb3.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb3);
break
;
case "System.Int32": //Int
TextBox tb4 = new TextBox();
tb4.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb4);
break
;
case "System.Int16": //smallInt
TextBox tb5 = new TextBox();
tb5.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb5);
break
;
case "System.Byte": //tinyInt
TextBox tb6 = new TextBox();
tb6.DataBinding += new EventHandler(tb_DataBinding);
container.Controls.Add(tb6);
break
;
case "System.DateTime": //DateTime
break;
}
#endregion
}
break
;
//set the footer style
case
ListItemType.Footer:
container.Controls.Add(lc);
break
;
}
#endregion
}

#endregion
#region
Events Raised By The InstantiateIn Methods Implementation
///
<summary>
/// Label Binding Data Event

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void lc_DataBinding(object sender, EventArgs e)
{
if (columnnumber != -1)
{
Literal literal = (Literal)sender;
DataRowView
container = (DataRowView)((DataGridItem)literal.NamingContainer).DataItem;
literal.Text = container.Row.ItemArray[columnnumber].ToString();
Regex
re = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

if
(re.IsMatch(literal.Text)) // for email address add a mailto: hyperlink
{
literal.Text = "<a href=mailto:" + literal.Text + ">" + literal.Text + "</a>"
}
}
}

///
<summary>
/// Event Is Raised To Find The Description Of UniqueIdentifiers

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void lc_SearchDataBinding(object sender, EventArgs e)
{
if (!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataColumnSearch], null))
{
Literal literal = (Literal)sender;
DataRowView
container = (DataRowView)((DataGridItem)literal.NamingContainer).DataItem;
guid = container.Row.ItemArray[columnnumber].ToString();
literal.ID = guid;
literal.Text = this.SearchDataTable(this.PropertyCollection[EMSDataGridExtendedProperties.DataTable], this.PropertyCollection[EMSDataGridExtendedProperties.DataColumnSearch], this.PropertyCollection[EMSDataGridExtendedProperties.DataTextField], guid);
}
else

{
throw new Exception("Search Data Column Not Set For DataTable " + ((DataTable)this.PropertyCollection[EMSDataGridExtendedProperties.DataTable]).TableName + " For Column " + columnname + " i.e. " + columncaption);
}
}

///
<summary>
/// Event Is Raised To Set The Default Selected Value

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void lc_SelectedDropDown(object sender, EventArgs e)
{
Literal literal = (Literal)sender;
DataRowView
container = (DataRowView)((DataGridItem)literal.NamingContainer).DataItem;
if
(!object.Equals(container.Row.ItemArray[columnnumber], Guid.Empty))
{
literal.Text = container.Row.ItemArray[columnnumber].ToString();
}
//this.strSelectedValue = container.Row.ItemArray[columnnumber].ToString();
}

///
<summary>
/// This Event Is Used For Selected DropDown

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void ddl_SelectedDropDown(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
DataRowView
container = (DataRowView)((DataGridItem)ddl.NamingContainer).DataItem;
//ddl.SelectedValue = this.strSelectedValue;

//this.strSelectedValue = string.Empty;
}

///
<summary>
/// Used To Set The Value For The TextBox Based On The DataType

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void tb_DataBinding(object sender, EventArgs e)
{
if (columnnumber != -1)
{
TextBox tb = (TextBox)sender;
DataRowView
container = (DataRowView)((DataGridItem)tb.NamingContainer).DataItem;

tb.Text = container.Row.ItemArray[columnnumber].ToString();

if
(!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.ReadOnly], null))
{
if (PropertyCollection[EMSDataGridExtendedProperties.ReadOnly].GetType().ToString() != "System.Boolean")
{
//TODO: Please Generlize This As Well
if
(container.Row[PropertyCollection[EMSDataGridExtendedProperties.ReadOnly].ToString()].GetType().ToString() == "System.Boolean")
{
bool blnFlag = (bool)container.Row[PropertyCollection[EMSDataGridExtendedProperties.ReadOnly].ToString()];

tb.ReadOnly = blnFlag;
//Setting ReadOnly Style Of The TextBox

if
(blnFlag)
{
if (!Object.Equals(PropertyCollection[EMSDataGridExtendedProperties.ReadOnlyStyle], null))
{
tb.CssClass = PropertyCollection[EMSDataGridExtendedProperties.ReadOnlyStyle].ToString();
}
else

{
tb.CssClass = READONLYTEXTBOXSTYLE;
}
}
}
}
}
}
}
///
<summary>
/// Used To Set The Value For The TextBox Based On The DataType

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void tb7_DataBinding(object sender, EventArgs e)
{
if (columnnumber != -1)
{
TextBox tb = (TextBox)sender;
DataRowView
container = (DataRowView)((DataGridItem)tb.NamingContainer).DataItem;

tb.Text = GetValidDate(container.Row.ItemArray[columnnumber]).ToString();
tb.ReadOnly = true;
tb.CssClass = READONLYTEXTBOXSTYLE;
}
}

///
<summary>
/// Used To Set The CheckBox Value

///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void cb_DataBinding(object sender, EventArgs e)
{
if (columnnumber != -1)
{
CheckBox cb = (CheckBox)sender;
DataRowView
container = (DataRowView)((DataGridItem)cb.NamingContainer).DataItem;
if
(!object.Equals(container.Row.ItemArray[columnnumber], DBNull.Value))
{
cb.Checked = (bool)container.Row.ItemArray[columnnumber];
}
}
}

#endregion
#region
Helper Function Used By This Class
///
<summary>
/// Helper Function Used Populate The DropDown Box

///
</summary>
///
<param name="ddl"></param>
private
void BindDropDown(DropDownList ddl)
{
if (!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataTable], null))
{
DataTable dt = (DataTable)this.PropertyCollection[EMSDataGridExtendedProperties.DataTable];

if
(!object.Equals(dt.Rows[0][0], DBNull.Value))
{
DataRow dr = dt.NewRow();
dr[0] = DBNull.Value;
dr[1] = DROPDOWNDEFAULTTEXT;
dt.Rows.InsertAt(dr, 0);
}

ddl.DataSource = dt;

if
(!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataValueField], null))
{
ddl.DataValueField = this.PropertyCollection[EMSDataGridExtendedProperties.DataValueField].ToString();
}
else

{
throw new Exception("Following Drop Down List Text Field Not Set For DataTable " + dt.TableName + " Column " + columnname + " i.e. " + columncaption);
}

if
(!object.Equals(this.PropertyCollection[EMSDataGridExtendedProperties.DataTextField], null))
{
ddl.DataTextField = this.PropertyCollection[EMSDataGridExtendedProperties.DataTextField].ToString();
}
else

{
throw new Exception("Following Drop Down List Text Field Not Set For DataTable " + dt.TableName + " Column " + columnname + " i.e. " + columncaption);
}
ddl.DataBind();
}
else

{
throw new Exception("Data Table Not Set For The Drop Down Box " + columnname + " i.e. " + columncaption);
}
}
///
<summary>
/// Helper Function Used To Set The Description For The Guid

///
</summary>
///
<param name="objDataTable"></param>
///
<param name="objDataColumn"></param>
///
<param name="strId"></param>
///
<returns></returns>
private
string SearchDataTable(object objDataTable, object objDataColumn, object objDataText, string strId)
{
//Checking if any ID Exists In Column
if
(strId.Length == 0)
{
return string.Empty;
}

//

if
(!object.Equals(objDataTable, null))
{
if (!object.Equals(objDataColumn, null))
{
DataRow[] dr = ((DataTable)objDataTable).Select(objDataColumn.ToString() + "='" + strId + "'");
if
(dr.Length == 0)
{
throw new ArgumentException(" Unable To Replace " + objDataColumn.ToString() + " Column Of DataTable " + ((DataTable)objDataTable).TableName + " With Description In Data Grid");
}
else

{
return dr[0][objDataText.ToString()].ToString();
//return dr[0][1].ToString();                        
}
}
else

{
return string.Empty;
}
}
else

{
return string.Empty;
}
}
///
<summary>
/// Helper Function Used For Date Conversion

///
</summary>
///
<param name="dtDate"></param>
///
<returns></returns>
public
DateTime DateConvertor(string strDate)
{
//TODO: Get It From The Ticket
return
DateTime.ParseExact(strDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None);
}
///
<summary>
/// Helper Function Used For Date Conversion

///
</summary>
///
<param name="dtDate"></param>
///
<returns></returns>
public
string DateConvertor(DateTime dtDate)
{
return dtDate.ToString("dd/MM/yyyy");
}
///
<summary>
/// Helper Function Used For DataRow Value Conversion

///
</summary>
///
<param name="objDate"></param>
///
<returns></returns>
private
object GetValidDate(object objDate)
{
if (objDate.Equals(DBNull.Value))
{
return objDate;
}
else

{
return this.DateConvertor((DateTime)objDate);
}
}
///
<summary>
/// Helper Function Used For DataRow Value Conversion

///
</summary>
///
<param name="strValue"></param>
///
<returns></returns>
private
object GetValidValue(string strValue)
{
strValue = strValue.ToString().Trim();
if
(strValue.Length == 0)
{
return DBNull.Value;
}
else

{
return strValue;
}
}
#endregion
}
}
. . .