Hello Friends,
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
4 Answers, 1 is accepted
0
vinod
Top achievements
Rank 1
answered on 13 Oct 2008, 04:55 AM
Hello Friends,
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
0
vinod
Top achievements
Rank 1
answered on 13 Oct 2008, 06:17 AM
Hello Friends,
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
0
vinod
Top achievements
Rank 1
answered on 13 Oct 2008, 07:38 AM
Hello Friends,
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
My Code behind page Source code is given below
#region Namespace Defined Here
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using dwtDAL;
using Telerik.Web.UI;
using RadDatePickerEditorClass;
#endregion
#region Global Object Defined Here
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
SqlConnection _sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
//public string FilePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogPath"].ToString());
public string FilePath = HttpContext.Current.Server.MapPath("..\\Log\\ErrorFile.txt");
public int pageCount = Convert.ToInt32(ConfigurationManager.AppSettings["PageDisplay"]);
string _errorLink = ConfigurationManager.AppSettings["ErrorLink"];
string _employeeID = string.Empty;
string _fullName = string.Empty;
string _appointmentID = string.Empty;
string _appointment = string.Empty;
string _EntityID = string.Empty;
static string[] _atrFriendlyName = new string[100];
string _masterEntity = string.Empty;
#endregion
#region Page Page_Init Event Here
protected void Page_Init(object sender, System.EventArgs e)
{
}
#endregion
#region Page Load Event Here
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
if (!Page.IsPostBack)
{
BindToDataTable(RadComboEntity);
BindToDataTable(RadRowsEntity);
}
DefineGrid();
string _strEntityIDAttributes = RadComboEntity.SelectedValue.ToString();
string _strQueryAttributes = string.Empty;
_strQueryAttributes += " SELECT Attribute.AttributeID,Entity.EntityName,Attribute.EntityID , ";
_strQueryAttributes += " Attribute.ColumnName,Attribute.ColumnName,Attribute.FriendlyName, ";
_strQueryAttributes += " Attribute.FKEntityID,Attribute.IsEditable,Attribute.IsVisibleOnForm, ";
_strQueryAttributes += " Attribute.IsVisibleOnGrid,Attribute.IsAudited,Attribute.IsApprovalRequired, ";
_strQueryAttributes += " Attribute.IsEntityTitle,Attribute.GridDisplayOrder,Attribute.FormDisplayOrder, ";
_strQueryAttributes += " FKEntityName = (SELECT EntityName FROM Entity WHERE EntityID = Attribute.FKEntityID) ";
_strQueryAttributes += " FROM Attribute JOIN Entity ON Attribute.EntityID= Entity.EntityID ";
_strQueryAttributes += " WHERE Attribute.EntityID= @EntityIDAttributes ORDER BY Entity.EntityID ";
SqlAttGrid.SelectCommand = _strQueryAttributes;
if (ChkisEditableGrid(RadComboEntity.SelectedValue.ToString()))
{
radGridAttributes.MasterTableView.EditMode = GridEditMode.InPlace;
}
else
{
radGridAttributes.MasterTableView.EditMode = GridEditMode.PopUp;
}
}
#endregion
#region radTabEmployee_TabClick event here
protected void radTabEmployee_TabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.Value == "1")
{
radPageEntity.Visible = true;
radPageAttributes.Visible = false;
radPageRows.Visible = false;
}
if (e.Tab.Value == "2")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = true;
radPageRows.Visible = false;
}
if (e.Tab.Value == "3")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = false;
radPageRows.Visible = true;
}
}
#endregion
#region TO check Grid is Editable in which mode
public bool ChkisEditableGrid(string strEntityID)
{
string strEntityQuery = "SELECT * FROM Entity WHERE EntityID=@EntityID";
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlCommand _sqlCommand = new SqlCommand(strEntityQuery, _sqlConnection);
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = strEntityID;
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
DataSet ds = new DataSet();
_sqlAdapter.Fill(ds);
if (ds.Tables[0].Rows[0]["IsEditedInGrid"].ToString() == "True")
{
return true;
}
else
{
return false;
}
ds.Clear();
ds.Dispose();
}
#endregion
#region RadComboEntity,RadComboRows BindToDataTable Method Here
private void BindToDataTable(RadComboBox combo)
{
try
{
string _strQry = "SELECT EntityID,FriendlySingularName FROM Entity ORDER BY FriendlySingularName ";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
SqlDataAdapter adapter = new SqlDataAdapter(_strQry, con);
DataTable links = new DataTable();
adapter.Fill(links);
combo.DataTextField = "FriendlySingularName";
combo.DataValueField = "EntityID";
combo.DataSource = links;
combo.DataBind();
if (combo.SelectedIndex > 0)
{
combo.SelectedIndex = 0;
}
links.Clear();
links.Dispose();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
Server.Transfer(_errorLink + ex.Message.ToString());
}
}
#endregion
#region Global Object Defined Here
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
SqlConnection _sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
//public string FilePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogPath"].ToString());
public string FilePath = HttpContext.Current.Server.MapPath("..\\Log\\ErrorFile.txt");
public int pageCount = Convert.ToInt32(ConfigurationManager.AppSettings["PageDisplay"]);
string _errorLink = ConfigurationManager.AppSettings["ErrorLink"];
string _employeeID = string.Empty;
string _fullName = string.Empty;
string _appointmentID = string.Empty;
string _appointment = string.Empty;
string _EntityID = string.Empty;
static string[] _atrFriendlyName = new string[100];
string _masterEntity = string.Empty;
#endregion
#region Page Page_Init Event Here
protected void Page_Init(object sender, System.EventArgs e)
{
}
#endregion
#region Page Load Event Here
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
if (!Page.IsPostBack)
{
BindToDataTable(RadComboEntity);
BindToDataTable(RadRowsEntity);
}
DefineGrid();
}
#endregion
#region radTabEmployee_TabClick event here
protected void radTabEmployee_TabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.Value == "1")
{
radPageEntity.Visible = true;
radPageAttributes.Visible = false;
radPageRows.Visible = false;
}
if (e.Tab.Value == "2")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = true;
radPageRows.Visible = false;
}
if (e.Tab.Value == "3")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = false;
radPageRows.Visible = true;
}
}
#endregion
#region TO check Grid is Editable in which mode
public bool ChkisEditableGrid(string strEntityID)
{
string strEntityQuery = "SELECT * FROM Entity WHERE EntityID=@EntityID";
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlCommand _sqlCommand = new SqlCommand(strEntityQuery, _sqlConnection);
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = strEntityID;
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
DataSet ds = new DataSet();
_sqlAdapter.Fill(ds);
if (ds.Tables[0].Rows[0]["IsEditedInGrid"].ToString() == "True")
{
return true;
}
else
{
return false;
}
ds.Clear();
ds.Dispose();
}
#endregion
#region RadComboEntity,RadComboRows BindToDataTable Method Here
private void BindToDataTable(RadComboBox combo)
{
try
{
string _strQry = "SELECT EntityID,FriendlySingularName FROM Entity ORDER BY FriendlySingularName ";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
SqlDataAdapter adapter = new SqlDataAdapter(_strQry, con);
DataTable links = new DataTable();
adapter.Fill(links);
combo.DataTextField = "FriendlySingularName";
combo.DataValueField = "EntityID";
combo.DataSource = links;
combo.DataBind();
if (combo.SelectedIndex > 0)
{
combo.SelectedIndex = 0;
}
links.Clear();
links.Dispose();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
Server.Transfer(_errorLink + ex.Message.ToString());
}
}
#endregion
#region Dynamic Rows RadGridRow Section
protected void RadGridRow_ItemDataBound(object sender, GridItemEventArgs e)
{
}
#region Dynamic GridCreate Event
protected void DefineGrid()
{
try
{
RadGridRow.Controls.Clear();
RadGridRow.Columns.Clear();
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
RadGridRow.Width = Unit.Percentage(100);
RadGridRow.GridLines = GridLines.None;
//RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
RadGridRow.NeedDataSource += new GridNeedDataSourceEventHandler(RadGridRow_NeedDataSource);
//RadGridRow.ItemCommand += new GridCommandEventHandler(RadGridRow_ItemCommand);
RadGridRow.InsertCommand += new GridCommandEventHandler(RadGridRow_InsertCommand);
RadGridRow.UpdateCommand += new GridCommandEventHandler(RadGridRow_UpdateCommand);
RadGridRow.CancelCommand += new GridCommandEventHandler(RadGridRow_CancelCommand);
RadGridRow.DeleteCommand += new GridCommandEventHandler(RadGridRow_DeleteCommand);
RadGridRow.ItemCreated += new GridItemEventHandler(RadGridRow_ItemCreated);
RadGridRow.ItemDataBound += new GridItemEventHandler(RadGridRow_ItemDataBound);
RadGridRow.CreateColumnEditor += new GridCreateColumnEditorEventHandler(RadGridRow_CreateColumnEditor);
// RadGridRow.ColumnCreated += new GridColumnCreatedEventHandler(RadGridRow_ColumnCreated);
RadGridRow.Width = Unit.Percentage(100);
RadGridRow.AllowPaging = true;
RadGridRow.AutoGenerateColumns = false;
RadGridRow.MasterTableView.AutoGenerateColumns = false;
RadGridRow.ClientSettings.AllowDragToGroup = true;
RadGridRow.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
RadGridRow.ShowStatusBar = true;
DataTable dt = new DataTable();
String strWorksitePositionManagerEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsWorksitePositionManagerEntityname = new DataSet();
dsWorksitePositionManagerEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strWorksitePositionManagerEntityname);
strWorksitePositionManagerEntityname = dsWorksitePositionManagerEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
dsWorksitePositionManagerEntityname.Dispose();
SqlCommand _sqlCommand;
//This is Only For WorksitePositionManager Start
if (strWorksitePositionManagerEntityname == "WorksitePositionManager")
{
string _strSqlWorksitePositionManager = " select WorksitePositionManager.WorksitePositionManagerID as [WorksitePositionManagerID~0],";
_strSqlWorksitePositionManager += " WorksitePositionManager.RowName as [RowName~0],";
_strSqlWorksitePositionManager += " WorksitePositionManager.StartDate as [StartDate~0], ";
_strSqlWorksitePositionManager += " WorksitePositionManager.EndDate as [EndDate~0],";
_strSqlWorksitePositionManager += " WorksitePosition.Rowname as [RowName~76],";
_strSqlWorksitePositionManager += " (select Rowname from WorksitePosition ";
_strSqlWorksitePositionManager += " where WorksitePositionID= WorksitePositionManager.ManagerWspID) ";
_strSqlWorksitePositionManager += " as [ManagerWorkSitePosition~76~1] from WorksitePositionManager inner join WorksitePosition ";
_strSqlWorksitePositionManager += " on WorksitePositionManager.WorksitePositionID = WorksitePosition.WorksitePositionID ";
_sqlCommand = new SqlCommand(_strSqlWorksitePositionManager, _sqlConnection);
}
//This is Only For WorksitePositionManager End
else
{
_sqlCommand = new SqlCommand("BuildDynamicRowsQuerry", _sqlConnection);
_sqlCommand.CommandType = CommandType.StoredProcedure;
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = _intEntityID;
}
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
_sqlAdapter.Fill(dt);
_sqlConnection.Close();
string StrSqlTablePk = "SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (select EntityName from Entity where EntityID='" + _intEntityID + "'))";
DataSet dsPktable = new DataSet();
dsPktable = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlTablePk);
string strTablePKName = string.Empty;
strTablePKName = dsPktable.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
dsPktable.Clear();
dsPktable.Dispose();
RadGridRow.MasterTableView.DataKeyNames = new string[] { strTablePKName + "~0" };//as Column Name In stored procedure
for (int i = 0; i < dt.Columns.Count; i++)
{
ListItem Item = new ListItem(dt.Columns[i].ToString(), dt.Columns[i].ToString());
string[] arr = dt.Columns[i].ToString().Split('~'); // split the string's spaces
string strColumnName = arr[0].ToString();
string strChkColumnType = arr[1].ToString();
String strGridColumnName = Item.Text; ;
string StrEntityName = string.Empty;
string strPKName = string.Empty;
string strColName = string.Empty;
if (strChkColumnType != "0")//FOR FKEntityID CHECK
{
String strSqlEntityname = "select EntityName from Entity where EntityID='" + strChkColumnType + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
StrEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
dsEntityname.Dispose();
string StrSqlColNameTEMP = "(SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (Select EntityName From Entity Where EntityID = '" + strChkColumnType + "')) ) C WHERE cid = 2) ";
DataSet dsColName = new DataSet();
dsColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlColNameTEMP);
strGridColumnName = dsColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
dsColName.Clear();
dsColName.Dispose();
DataSet dsPk = new DataSet();
DataSet dstColName = new DataSet();
string strSqlPk = " SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ";
string strSqlColName = " SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ) C WHERE cid = 2 ";
dsPk = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlPk);
strPKName = dsPk.Tables[0].Rows[0]["NAME"].ToString();
dsPk.Clear();
dsPk.Dispose();
dstColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlColName);
strColName = dstColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim(); ;
dstColName.Clear();
dstColName.Dispose();
}
if ((dt.Columns[i].DataType.ToString() == "System.String") || (dt.Columns[i].DataType.ToString() == "System.Int32"))
{
if (strChkColumnType != "0")//FOR FKEntityID CHECK
{
if (dt.Columns[i].ToString() != "ManagerWorkSitePosition~76~1")//This is for WorksitePositionManager
{
string templateColumnName = StrEntityName;
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyItemTemplate(StrEntityName + "MyItemTemplate" + i.ToString(), Item.Value.ToString());
templateColumn.EditItemTemplate = new MyEditTemplate(StrEntityName + "MyEditTemplate" + i.ToString(), StrEntityName, strPKName, strColName, Item.Value.ToString(), strColumnName);
RadGridRow.MasterTableView.Columns.Add(templateColumn);
templateColumn.HeaderText = templateColumnName;
templateColumn.UniqueName = strColumnName;
}
else
{
string templateColumnName = "ManagerWorkSitePositon";
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyItemTemplateManager(Item.Value.ToString());
templateColumn.EditItemTemplate = new MyEditTemplateManager(Item.Value.ToString());
RadGridRow.MasterTableView.Columns.Add(templateColumn);
templateColumn.HeaderText = templateColumnName;
templateColumn.UniqueName = strColumnName;
}
}
else
{
if (strColumnName != "FullName")
{
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
if (strTablePKName == strColumnName)
{
boundColumn.ReadOnly = true;//To Hide Pk ID In Edit Form
}
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
}
}
else if (dt.Columns[i].DataType.ToString() == "System.Boolean")
{
GridCheckBoxColumn boundColumn = new GridCheckBoxColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
else if (dt.Columns[i].DataType.ToString() == "System.DateTime")
{
GridDateTimeColumn boundColumn = new GridDateTimeColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
boundColumn.DataFormatString = "{0:d}";
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
}
RadGridRow.DataSource = dt;
dt.Dispose();
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
GridButtonColumn BtnDelete = new GridButtonColumn();
BtnDelete.ButtonType = GridButtonColumnType.ImageButton;
RadGridRow.MasterTableView.Columns.Add(BtnDelete);
// BtnDelete.HeaderText="Delete";
BtnDelete.Text = "Delete";
BtnDelete.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
BtnDelete.ItemStyle.VerticalAlign = VerticalAlign.Middle;
BtnDelete.CommandName = "Delete";
BtnDelete.ConfirmDialogType = GridConfirmDialogType.RadWindow;
BtnDelete.ConfirmText = "Are You Sure to Delete This Record?";
BtnDelete.ConfirmTitle = "Delete";
RadGridRow.MasterTableView.Columns.FindByUniqueName(strTablePKName).Visible = false;
// RadGridRow.Columns[0].Visible = false;
RadGridRow.ClientSettings.Scrolling.AllowScroll = true;
RadGridRow.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(380);
RadGridRow.MasterTableView.EditMode = GridEditMode.EditForms;
// RadGridRow.MasterTableView.EditFormSettings.EditColumn.ButtonType = GridButtonColumnType.ImageButton;
RadGridRow.MasterTableView.EditFormSettings.EditColumn.InsertImageUrl = "../Admin/Update.gif";
RadGridRow.MasterTableView.EditFormSettings.EditColumn.UpdateImageUrl = "../Admin/Update.gif";
RadGridRow.AllowSorting = true;
//RadGridRow.AllowPaging = true;
//RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
//RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
//RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
//RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
//RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
//RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
//RadGridRow.AllowPaging = true;
//RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
//RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
//RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
//RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
//RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
// RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric ;
// RadGridRow.PagerStyle.PagerTextFormat = "Side: {4} | Viser brukere {2} til {3} av totalt {5} " ;
// RadGridRow.PagerStyle.NextPagesToolTip = "Neste sider" ;
//RadGridRow.PagerStyle.NextPageToolTip = "Neste sider" ;
//RadGridRow.PagerStyle.PrevPagesToolTip = "Forrige sider";
//RadGridRow.PagerStyle.PrevPageToolTip = "Forrige side" ;
//RadGridRow.PagerStyle.NextPageText = "»" ;
//RadGridRow.PagerStyle.PrevPageText = "«" ;
//RadGridRow.PagerStyle.EnableSEOPaging = true ;
//RadGridRow.PagerStyle.SEOPagingQueryStringKey = "side";
RadGridRow.PageSize = pageCount;
RadGridRow.MasterTableView.PageSize = pageCount;
RadGridRow.MasterTableView.CommandItemSettings.RefreshText = "";
RadGridRow.MasterTableView.CommandItemSettings.AddNewRecordText = "Add New";
RadGridRow.Rebind();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Error . Reason: " + ex.Message));
}
}
#endregion End GridBind Event
#region Grid Need Source Event Here
protected void RadGridRow_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
}
#endregion End Grid Need Source Event
#region Grid Cancel Event Here
private void RadGridRow_CancelCommand(object source, GridCommandEventArgs e)
{
}
#endregion End Cancel Evente Event
#region Grid RadGridRow_ItemCreated Event Here
protected void RadGridRow_ItemCreated(object sender, GridItemEventArgs e)
{
}
#endregion End RadGridRow_ItemCreated Event
#region Grid UpdateCommand Event Here
private void RadGridRow_UpdateCommand(object source, GridCommandEventArgs e)
{
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
ArrayList arrayListWhPkColumn = new ArrayList();
ArrayList arrayListWhPkValues = new ArrayList();
ArrayList arrayListDTColumn = new ArrayList();
ArrayList arrayListDTValues = new ArrayList();
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
string editorText = "unknown";
object editorValue = null;
if (editor is GridTextColumnEditor)
{
if (editor is GridDateTimeColumnEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else if (editor is RadDatePickerEditorClass.RadDatePickerEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
if (editor is GridBoolColumnEditor)
{
editorText = (editor as GridBoolColumnEditor).Value.ToString();
editorValue = (editor as GridBoolColumnEditor).Value;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
}
}
string _strWithoutPKColName = string.Empty;
string _strWithoutPKColvalue = string.Empty;
for (int i = 1; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 2 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + ",";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i];
}
}
for (int i = 1; i < arrayListWhPkValues.Count; i++)
{
if (arrayListWhPkValues.Count != 2 && i < arrayListWhPkValues.Count - 1)
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i] + ",";
}
else
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i];
}
}
string strSqlWithtFk = " select * from Attribute where EntityID='" + _intEntityID + "' and (FkEntityid is not null and FkEntityid !=0) ";
DataTable dtColumnInfoWithFk = new DataTable();
dtColumnInfoWithFk = SqlHelper.GetDataTable(_sqlConnectionString, strSqlWithtFk);
ArrayList arrayListWithPkColumn = new ArrayList();
ArrayList arrayListWithPkValues = new ArrayList();
for (int i = 0; i < dtColumnInfoWithFk.Rows.Count; i++)
{
string _strColumnNameValue = string.Empty;
string _strColName = string.Empty;
_strColName = dtColumnInfoWithFk.Rows[i]["ColumnName"].ToString();
arrayListWithPkColumn.Add(_strColName);
string _strFkColID = dtColumnInfoWithFk.Rows[i]["FKEntityID"].ToString();
DataTable _dtTableName = new DataTable();
_dtTableName = SqlHelper.GetDataTable(_sqlConnectionString, "select EntityName From Entity where EntityID='" + _strFkColID + "'");
string _drpSelectedvalue = String.Empty;
if (_strEntityName != "WorksitePositionManager")
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
else
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = string.Empty;
if (i == 1)
{
_strTableName = "managerWorksitePosition"; //This is for WorksitePositionManager
}
else
{
_strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
}
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
}
_strWithoutPKColName = string.Empty;
for (int i = 0; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 1 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + "=" + arrayListWhPkValues[i].ToString() + " ,";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i].ToString() + "=" + arrayListWhPkValues[i].ToString();
}
}
string _strColNamePK = string.Empty;
for (int i = 0; i < arrayListWithPkColumn.Count; i++)
{
if (arrayListWithPkColumn.Count != 1 && i < arrayListWithPkColumn.Count - 1)
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i].ToString() + "=" + arrayListWithPkValues[i].ToString() + " ,";
}
else
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i].ToString() + "=" + arrayListWithPkValues[i].ToString() + "";
}
}
string _strSqlUpdateColumn = string.Empty;
string _strSqlUpdateColumnValues = string.Empty;
if (arrayListWithPkColumn.Count == 0 && arrayListWithPkValues.Count == 0)
{
_strSqlUpdateColumn = _strWithoutPKColName;
}
else
{
_strSqlUpdateColumn = _strWithoutPKColName + "," + _strColNamePK;
}
string _strPKColumnNameUpdate = editedItem.OwnerTableView.DataKeyNames[0].ToString();
string _strPKColumnNameValueUpdate = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex][_strPKColumnNameUpdate].ToString();
// string _strSqlUpdateQuery = "Update " + _strEntityName + " set " + _strSqlUpdateColumn + " where " + arrayListWhPkColumn[0].ToString() + "=" + arrayListWhPkValues[0].ToString() + " ";
string _strSqlUpdateQuery = "Update " + _strEntityName + " set " + _strSqlUpdateColumn + " where " + _strPKColumnNameUpdate.Replace("~0", "") + "='" + _strPKColumnNameValueUpdate + "' ";
SqlCommand _cmdUpdateDetails = new SqlCommand(_strSqlUpdateQuery, _sqlConnection);
for (int i = 0; i < arrayListDTColumn.Count; i++)
{
if (arrayListDTColumn.Count != 0 && arrayListDTValues.Count != 0)
{
_cmdUpdateDetails.Parameters.Add(arrayListDTColumn[i].ToString(), SqlDbType.DateTime).Value = arrayListDTValues[i].ToString();
}
}
try
{
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_cmdUpdateDetails.ExecuteNonQuery();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End UpdateCommand Event
#region Grid Insert Command Event Here
private void RadGridRow_InsertCommand(object source, GridCommandEventArgs e)
{
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
ArrayList arrayListWhPkColumn = new ArrayList();
ArrayList arrayListWhPkValues = new ArrayList();
ArrayList arrayListDTColumn = new ArrayList();
ArrayList arrayListDTValues = new ArrayList();
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
string editorText = "unknown";
object editorValue = null;
if (editor is GridTextColumnEditor)
{
if (editor is GridDateTimeColumnEditor )
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else if (editor is RadDatePickerEditorClass.RadDatePickerEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
if (editor is GridBoolColumnEditor)
{
editorText = (editor as GridBoolColumnEditor).Value.ToString();
editorValue = (editor as GridBoolColumnEditor).Value;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
}
}
string _strWithoutPKColName = string.Empty;
string _strWithoutPKColvalue = string.Empty;
for (int i = 0; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 1 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + ",";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i];
}
}
for (int i = 0; i < arrayListWhPkValues.Count; i++)
{
if (arrayListWhPkValues.Count != 1 && i < arrayListWhPkValues.Count - 1)
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i] + ",";
}
else
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i];
}
}
string strSqlWithtFk = " select * from Attribute where EntityID='" + _intEntityID + "' and (FkEntityid is not null and FkEntityid !=0) ";
DataTable dtColumnInfoWithFk = new DataTable();
dtColumnInfoWithFk = SqlHelper.GetDataTable(_sqlConnectionString, strSqlWithtFk);
ArrayList arrayListWithPkColumn = new ArrayList();
ArrayList arrayListWithPkValues = new ArrayList();
for (int i = 0; i < dtColumnInfoWithFk.Rows.Count; i++)
{
string _strColumnNameValue = string.Empty;
string _strColName = string.Empty;
_strColName = dtColumnInfoWithFk.Rows[i]["ColumnName"].ToString();
arrayListWithPkColumn.Add(_strColName);
string _strFkColID = dtColumnInfoWithFk.Rows[i]["FKEntityID"].ToString();
DataTable _dtTableName = new DataTable();
_dtTableName = SqlHelper.GetDataTable(_sqlConnectionString, "select EntityName From Entity where EntityID='" + _strFkColID + "'");
string _drpSelectedvalue = String.Empty;
//This is for WorksitePositionManager
if (_strEntityName != "WorksitePositionManager")
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
//This is for WorksitePositionManager End
else
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = string.Empty;
if (i == 1)
{
_strTableName = "managerWorksitePosition";
}
else
{
_strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
}
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
}
string _strColNamePK = string.Empty;
string _strColvaluePK = string.Empty;
for (int i = 0; i < arrayListWithPkColumn.Count; i++)
{
if (arrayListWithPkColumn.Count != 1 && i < arrayListWithPkColumn.Count - 1)
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i] + ",";
}
else
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i];
}
}
for (int i = 0; i < arrayListWithPkValues.Count; i++)
{
if (arrayListWithPkValues.Count != 1 && i < arrayListWithPkValues.Count - 1)
{
_strColvaluePK = _strColvaluePK + arrayListWithPkValues[i] + ",";
}
else
{
_strColvaluePK = _strColvaluePK + arrayListWithPkValues[i];
}
}
string _strSqlInsertColumn = string.Empty;
string _strSqlInsertColumnValues = string.Empty;
if (arrayListWithPkColumn.Count == 0 && arrayListWithPkValues.Count == 0)
{
_strSqlInsertColumn = _strWithoutPKColName;
_strSqlInsertColumnValues = _strWithoutPKColvalue;
}
else
{
_strSqlInsertColumn = _strWithoutPKColName + "," + _strColNamePK;
_strSqlInsertColumnValues = _strWithoutPKColvalue + "," + _strColvaluePK;
}
string _strSqlInsertQuery = "Insert Into " + _strEntityName + "(" + _strSqlInsertColumn + ") values(" + _strSqlInsertColumnValues + ")";
SqlCommand _cmdInsertDetails = new SqlCommand(_strSqlInsertQuery, _sqlConnection);
for (int i = 0; i < arrayListDTColumn.Count; i++)
{
if (arrayListDTColumn.Count != 0 && arrayListDTValues.Count != 0)
{
_cmdInsertDetails.Parameters.Add(arrayListDTColumn[i].ToString(), SqlDbType.DateTime).Value = DateTime.Parse(arrayListDTValues[i].ToString()).ToShortDateString();
}
}
try
{
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_cmdInsertDetails.ExecuteNonQuery();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End InsertCommand Event
#region MyEditTemplate Class Start Here
private class MyEditTemplate : ITemplate, IBindableTemplate
{
protected Label label;
protected RadComboBox combobox;
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
private string colname;
private string radComboID;
private string tempStrEntityName;
private string tempStrPKName;
private string tempStrColName;
private string tempStrDataCol;
private string TemplateColumnUniqueName;
public MyEditTemplate(string cName, string StrEntityName, string StrPKName, string StrColName, string StrDataCol, string ColumnUniqueName)
{
colname = cName;
radComboID = cName;
tempStrEntityName = StrEntityName;
tempStrPKName = StrPKName;
tempStrColName = StrColName;
tempStrDataCol = StrDataCol;
TemplateColumnUniqueName = ColumnUniqueName;
}
public void combobox_DataBinding(object sender, EventArgs e)
{
RadComboBox cc = (RadComboBox) sender;
cc.Skin = "DwtDemo";
cc.EnableEmbeddedSkins = false;
SqlDataSource cmd = new SqlDataSource();
cmd.ConnectionString = _sqlConnectionString;
cmd.SelectCommand = "select * from " + tempStrEntityName;
cc.DataSource = cmd;
cc.DataTextField = tempStrColName;
cc.DataValueField = tempStrPKName;
}
public void label_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
lblData.Visible = false;
try
{
GridEditFormItem container = (GridEditFormItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[tempStrDataCol].ToString();
if (label.Text.ToString() != "")
{
combobox.Items.FindItemByText(label.Text.ToString()).Selected = true;
}
}
catch (Exception ex)
{
// LogHelper.ErrorLog(Ex.Message.ToString(), FilePath);
}
}
public void InstantiateIn(System.Web.UI.Control container)
{
combobox = new RadComboBox();
combobox.ID = tempStrEntityName;
combobox.Skin = "DwtDemo";
combobox.EnableEmbeddedSkins = false;
// combobox.SkinID = "WebBlue";
combobox.DataBinding += new EventHandler(combobox_DataBinding);
container.Controls.Add(combobox);
label = new Label();
label.ID = "lbl" + tempStrEntityName;
label.DataBinding += new EventHandler(label_DataBinding);
container.Controls.Add(label);
}
public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
System.Collections.Specialized.OrderedDictionary od = new System.Collections.Specialized.OrderedDictionary();
return od;
}
}
#endregion MyEditTemplate Class End Here
//This is for WorksitePositionManager
#region MyEditTemplateManager Class Start Here
private class MyEditTemplateManager : ITemplate, IBindableTemplate
{
protected Label label;
protected RadComboBox combobox;
private string tempStrDataCol = string.Empty;
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
public MyEditTemplateManager(string StrDataCol)
{
tempStrDataCol = StrDataCol;
}
public void combobox_DataBinding(object sender, EventArgs e)
{
RadComboBox cc = (RadComboBox) sender;
cc.Skin = "DwtDemo";
cc.EnableEmbeddedSkins = false;
SqlDataSource cmd = new SqlDataSource();
cmd.ConnectionString = _sqlConnectionString;
cmd.SelectCommand = "select * from WorkSitePosition";
cc.DataSource = cmd;
cc.DataTextField = "RowName";
cc.DataValueField = "WorksitePositionID";
}
public void label_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
lblData.Visible = false;
try
{
GridEditFormItem container = (GridEditFormItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[tempStrDataCol].ToString();
if (label.Text.ToString() != "")
{
combobox.Items.FindItemByText(label.Text.ToString()).Selected = true;
}
}
catch (Exception ex)
{
// LogHelper.ErrorLog(Ex.Message.ToString(), FilePath);
}
}
public void InstantiateIn(System.Web.UI.Control container)
{
combobox = new RadComboBox();
combobox.ID = "managerWorksitePosition";
combobox.Skin = "DwtDemo";
combobox.EnableEmbeddedSkins = false;
// combobox.SkinID = "WebBlue";
combobox.DataBinding += new EventHandler(combobox_DataBinding);
container.Controls.Add(combobox);
label = new Label();
label.ID = "lblmanagerWorksitePosition";
label.DataBinding += new EventHandler(label_DataBinding);
container.Controls.Add(label);
}
public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
System.Collections.Specialized.OrderedDictionary od = new System.Collections.Specialized.OrderedDictionary();
return od;
}
}
#endregion MyEditTemplate Class End Here
#region MyItemTemplate Class Start Here
private class MyItemTemplate : ITemplate
{
protected Label label;
private string colname;
private string MyItemTemplateLbl;
public MyItemTemplate(string cName, string lblValue)
{
colname = cName;
MyItemTemplateLbl = lblValue;
}
public void textBox_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
GridDataItem container = (GridDataItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[MyItemTemplateLbl].ToString();
}
public void InstantiateIn(System.Web.UI.Control container)
{
label = new Label();
label.DataBinding += new EventHandler(textBox_DataBinding);
// textBox.Text = txtBoxID;
// textBox.ID = txtBoxID;
container.Controls.Add(label);
}
}
#endregion MyItemTemplate Class End Here
//This is for WorksitePositionManager
#region MyItemTemplateMaNAGER Class Start Here
private class MyItemTemplateManager : ITemplate
{
protected Label label;
private string colname;
private string MyItemTemplateLbl;
public MyItemTemplateManager(string lblValue)
{
colname = "managerWorksitePosition";
MyItemTemplateLbl = lblValue;
}
public void textBox_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
GridDataItem container = (GridDataItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[MyItemTemplateLbl].ToString();
}
public void InstantiateIn(System.Web.UI.Control container)
{
label = new Label();
label.DataBinding += new EventHandler(textBox_DataBinding);
// textBox.Text = txtBoxID;
// textBox.ID = txtBoxID;
container.Controls.Add(label);
}
}
#endregion MyItemTemplate Class End Here
#region RadRowsEntity_SelectedIndexChanged Event
#region RadRowsEntity_SelectedIndexChangedEvent Here
protected void RadRowsEntity_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
// RadGridRow.Controls.Clear();
// _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
DefineGrid();
}
#endregion
#endregion RadRowsEntity_SelectedIndexChanged Event End Here
#region Display Message For Exception handling Event
private void DisplayMessage(string text)
{
RadGridRow.Controls.Add(new LiteralControl(text));
}
#endregion Display Message For Exception handling Event End here
#region Grid PreRender Event
protected void RadGridRow_PreRender(object sender, EventArgs e)
{
//RadGridRow.Rebind();
}
#endregion Grid PreRender Event
#region Start Delete Event
private void RadGridRow_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
int _intDelEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intDelEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
// editedItem.OwnerTableView.DataKeyNames[0].ToString()
string _strDataKeyName = e.Item.OwnerTableView.DataKeyNames[0].ToString();
string[] _strdataColumnName = _strDataKeyName.Split('~');
string _strDataKeyNameValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][_strDataKeyName].ToString();
try
{
// _sqlConnection.ConnectionString = _sqlConnectionString;
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlTransaction _transaction = _sqlConnection.BeginTransaction();
string _strsql = "";
_strsql = "BEGIN TRANSACTION";
_strsql += " DELETE From " + _strEntityName + " Where " + _strdataColumnName[0].ToString() + " = '" + _strDataKeyNameValue + "'";
_strsql += " IF @@ERROR <>0 ROLLBACK TRANSACTION ";
_strsql += " ELSE COMMIT TRANSACTION";
SqlCommand _cmdDeleteEntity = new SqlCommand(_strsql, _sqlConnection);
_cmdDeleteEntity.Transaction = _transaction;
_cmdDeleteEntity.ExecuteNonQuery();
_transaction.Commit();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End Delete Events
#region Start CreateColumnEditor Event
private void RadGridRow_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
{
int _intCreateColEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
string _strSqlRadGridRow=" Select Entity.EntityID, sys.all_objects.Name AS EntityName,sys.all_columns.Name AS ColumnName, sys.types.Name AS DataType ";
_strSqlRadGridRow += " From sys.all_columns ";
_strSqlRadGridRow += " INNER JOIN sys.all_objects ON all_columns.object_id = sys.all_objects.object_id ";
_strSqlRadGridRow += " INNER JOIN sys.types ON sys.types.system_type_id = sys.all_columns.system_type_id ";
_strSqlRadGridRow += " INNER JOIN Entity On Entity.EntityName = sys.all_objects.Name ";
_strSqlRadGridRow += " WHERE sys.all_columns.NAME IN (SELECT ColumnName FROM Attribute WHERE EntityID IN (SELECT EntityID From Entity)) ";
_strSqlRadGridRow += " AND sys.types.name = 'DateTime' and EntityID ='" + _intCreateColEntityID + "'";
DataSet _dsDateTimeColumn = new DataSet();
_dsDateTimeColumn = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, _strSqlRadGridRow);
string strDateTimeColumnName = string.Empty;
for(int i=0;i<_dsDateTimeColumn.Tables[0].Rows.Count;i++)
{
strDateTimeColumnName = string.Empty;
strDateTimeColumnName = _dsDateTimeColumn.Tables[0].Rows[i]["ColumnName"].ToString().Trim().Replace("'","''");
if (e.Column.UniqueName.ToLower().Trim() == strDateTimeColumnName.ToLower())
{
e.ColumnEditor = new RadDatePickerEditorClass.RadDatePickerEditor();
}
}
_dsDateTimeColumn.Clear();
_dsDateTimeColumn.Dispose();
}
#endregion End CreateColumnEditor Events
protected void RadGridRow_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
if (e.Column is GridEditCommandColumn)
{
GridEditCommandColumn editcol = (GridEditCommandColumn)e.Column;
//editcol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton;
editcol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
editcol.ButtonType = GridButtonColumnType.ImageButton;
}
//if (e.Column is GridButtonColumn)
//{
// GridButtonColumn deletecol = (GridButtonColumn)e.Column;
// if (deletecol.UniqueName == "AutoGeneratedDeleteColumn")
// {
// deletecol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton;
// deletecol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
// }
//}
}
#region RadGridRow ItemCommand Event Here
protected void RadGridRow_ItemCommand(object source, GridCommandEventArgs e)
{
string str = e.CommandName.ToString();
if (e.CommandName == "Edit")
{
RadGridRow.MasterTableView.IsItemInserted = false;
}
else if (e.CommandName == "InitInsert")
{
RadGridRow.EditIndexes.Clear();
}
else if (e.CommandName == "RebindGrid")
{
RadGridRow.MasterTableView.Rebind();
}
}
#endregion End RadGridRow ItemCommand Section
#endregion End Dynamic Row All Events
i am Created RadGrid Dynamically........
Added Edit Column Runtime It Work Fine for Below Code.
But When i am change GridButtonColumnType to ImageButton
Edit From not Working Means grid not open in Edit Mode....
have a Look at this and please provide is possible solution With Example.
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
// col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Thanks in Advance......
Following Error message Appears When Edit GridButtonColumnType changed to ImageButton....
Error: [Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
My Code behind page Source code is given below
#region Namespace Defined Here
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using dwtDAL;
using Telerik.Web.UI;
using RadDatePickerEditorClass;
#endregion
#region Global Object Defined Here
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
SqlConnection _sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
//public string FilePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogPath"].ToString());
public string FilePath = HttpContext.Current.Server.MapPath("..\\Log\\ErrorFile.txt");
public int pageCount = Convert.ToInt32(ConfigurationManager.AppSettings["PageDisplay"]);
string _errorLink = ConfigurationManager.AppSettings["ErrorLink"];
string _employeeID = string.Empty;
string _fullName = string.Empty;
string _appointmentID = string.Empty;
string _appointment = string.Empty;
string _EntityID = string.Empty;
static string[] _atrFriendlyName = new string[100];
string _masterEntity = string.Empty;
#endregion
#region Page Page_Init Event Here
protected void Page_Init(object sender, System.EventArgs e)
{
}
#endregion
#region Page Load Event Here
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
if (!Page.IsPostBack)
{
BindToDataTable(RadComboEntity);
BindToDataTable(RadRowsEntity);
}
DefineGrid();
string _strEntityIDAttributes = RadComboEntity.SelectedValue.ToString();
string _strQueryAttributes = string.Empty;
_strQueryAttributes += " SELECT Attribute.AttributeID,Entity.EntityName,Attribute.EntityID , ";
_strQueryAttributes += " Attribute.ColumnName,Attribute.ColumnName,Attribute.FriendlyName, ";
_strQueryAttributes += " Attribute.FKEntityID,Attribute.IsEditable,Attribute.IsVisibleOnForm, ";
_strQueryAttributes += " Attribute.IsVisibleOnGrid,Attribute.IsAudited,Attribute.IsApprovalRequired, ";
_strQueryAttributes += " Attribute.IsEntityTitle,Attribute.GridDisplayOrder,Attribute.FormDisplayOrder, ";
_strQueryAttributes += " FKEntityName = (SELECT EntityName FROM Entity WHERE EntityID = Attribute.FKEntityID) ";
_strQueryAttributes += " FROM Attribute JOIN Entity ON Attribute.EntityID= Entity.EntityID ";
_strQueryAttributes += " WHERE Attribute.EntityID= @EntityIDAttributes ORDER BY Entity.EntityID ";
SqlAttGrid.SelectCommand = _strQueryAttributes;
if (ChkisEditableGrid(RadComboEntity.SelectedValue.ToString()))
{
radGridAttributes.MasterTableView.EditMode = GridEditMode.InPlace;
}
else
{
radGridAttributes.MasterTableView.EditMode = GridEditMode.PopUp;
}
}
#endregion
#region radTabEmployee_TabClick event here
protected void radTabEmployee_TabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.Value == "1")
{
radPageEntity.Visible = true;
radPageAttributes.Visible = false;
radPageRows.Visible = false;
}
if (e.Tab.Value == "2")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = true;
radPageRows.Visible = false;
}
if (e.Tab.Value == "3")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = false;
radPageRows.Visible = true;
}
}
#endregion
#region TO check Grid is Editable in which mode
public bool ChkisEditableGrid(string strEntityID)
{
string strEntityQuery = "SELECT * FROM Entity WHERE EntityID=@EntityID";
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlCommand _sqlCommand = new SqlCommand(strEntityQuery, _sqlConnection);
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = strEntityID;
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
DataSet ds = new DataSet();
_sqlAdapter.Fill(ds);
if (ds.Tables[0].Rows[0]["IsEditedInGrid"].ToString() == "True")
{
return true;
}
else
{
return false;
}
ds.Clear();
ds.Dispose();
}
#endregion
#region RadComboEntity,RadComboRows BindToDataTable Method Here
private void BindToDataTable(RadComboBox combo)
{
try
{
string _strQry = "SELECT EntityID,FriendlySingularName FROM Entity ORDER BY FriendlySingularName ";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
SqlDataAdapter adapter = new SqlDataAdapter(_strQry, con);
DataTable links = new DataTable();
adapter.Fill(links);
combo.DataTextField = "FriendlySingularName";
combo.DataValueField = "EntityID";
combo.DataSource = links;
combo.DataBind();
if (combo.SelectedIndex > 0)
{
combo.SelectedIndex = 0;
}
links.Clear();
links.Dispose();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
Server.Transfer(_errorLink + ex.Message.ToString());
}
}
#endregion
#region Global Object Defined Here
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
SqlConnection _sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
//public string FilePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogPath"].ToString());
public string FilePath = HttpContext.Current.Server.MapPath("..\\Log\\ErrorFile.txt");
public int pageCount = Convert.ToInt32(ConfigurationManager.AppSettings["PageDisplay"]);
string _errorLink = ConfigurationManager.AppSettings["ErrorLink"];
string _employeeID = string.Empty;
string _fullName = string.Empty;
string _appointmentID = string.Empty;
string _appointment = string.Empty;
string _EntityID = string.Empty;
static string[] _atrFriendlyName = new string[100];
string _masterEntity = string.Empty;
#endregion
#region Page Page_Init Event Here
protected void Page_Init(object sender, System.EventArgs e)
{
}
#endregion
#region Page Load Event Here
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
if (!Page.IsPostBack)
{
BindToDataTable(RadComboEntity);
BindToDataTable(RadRowsEntity);
}
DefineGrid();
}
#endregion
#region radTabEmployee_TabClick event here
protected void radTabEmployee_TabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.Value == "1")
{
radPageEntity.Visible = true;
radPageAttributes.Visible = false;
radPageRows.Visible = false;
}
if (e.Tab.Value == "2")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = true;
radPageRows.Visible = false;
}
if (e.Tab.Value == "3")
{
radPageEntity.Visible = false;
radPageAttributes.Visible = false;
radPageRows.Visible = true;
}
}
#endregion
#region TO check Grid is Editable in which mode
public bool ChkisEditableGrid(string strEntityID)
{
string strEntityQuery = "SELECT * FROM Entity WHERE EntityID=@EntityID";
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlCommand _sqlCommand = new SqlCommand(strEntityQuery, _sqlConnection);
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = strEntityID;
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
DataSet ds = new DataSet();
_sqlAdapter.Fill(ds);
if (ds.Tables[0].Rows[0]["IsEditedInGrid"].ToString() == "True")
{
return true;
}
else
{
return false;
}
ds.Clear();
ds.Dispose();
}
#endregion
#region RadComboEntity,RadComboRows BindToDataTable Method Here
private void BindToDataTable(RadComboBox combo)
{
try
{
string _strQry = "SELECT EntityID,FriendlySingularName FROM Entity ORDER BY FriendlySingularName ";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString());
SqlDataAdapter adapter = new SqlDataAdapter(_strQry, con);
DataTable links = new DataTable();
adapter.Fill(links);
combo.DataTextField = "FriendlySingularName";
combo.DataValueField = "EntityID";
combo.DataSource = links;
combo.DataBind();
if (combo.SelectedIndex > 0)
{
combo.SelectedIndex = 0;
}
links.Clear();
links.Dispose();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
Server.Transfer(_errorLink + ex.Message.ToString());
}
}
#endregion
#region Dynamic Rows RadGridRow Section
protected void RadGridRow_ItemDataBound(object sender, GridItemEventArgs e)
{
}
#region Dynamic GridCreate Event
protected void DefineGrid()
{
try
{
RadGridRow.Controls.Clear();
RadGridRow.Columns.Clear();
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
RadGridRow.Width = Unit.Percentage(100);
RadGridRow.GridLines = GridLines.None;
//RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
RadGridRow.NeedDataSource += new GridNeedDataSourceEventHandler(RadGridRow_NeedDataSource);
//RadGridRow.ItemCommand += new GridCommandEventHandler(RadGridRow_ItemCommand);
RadGridRow.InsertCommand += new GridCommandEventHandler(RadGridRow_InsertCommand);
RadGridRow.UpdateCommand += new GridCommandEventHandler(RadGridRow_UpdateCommand);
RadGridRow.CancelCommand += new GridCommandEventHandler(RadGridRow_CancelCommand);
RadGridRow.DeleteCommand += new GridCommandEventHandler(RadGridRow_DeleteCommand);
RadGridRow.ItemCreated += new GridItemEventHandler(RadGridRow_ItemCreated);
RadGridRow.ItemDataBound += new GridItemEventHandler(RadGridRow_ItemDataBound);
RadGridRow.CreateColumnEditor += new GridCreateColumnEditorEventHandler(RadGridRow_CreateColumnEditor);
// RadGridRow.ColumnCreated += new GridColumnCreatedEventHandler(RadGridRow_ColumnCreated);
RadGridRow.Width = Unit.Percentage(100);
RadGridRow.AllowPaging = true;
RadGridRow.AutoGenerateColumns = false;
RadGridRow.MasterTableView.AutoGenerateColumns = false;
RadGridRow.ClientSettings.AllowDragToGroup = true;
RadGridRow.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
RadGridRow.ShowStatusBar = true;
DataTable dt = new DataTable();
String strWorksitePositionManagerEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsWorksitePositionManagerEntityname = new DataSet();
dsWorksitePositionManagerEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strWorksitePositionManagerEntityname);
strWorksitePositionManagerEntityname = dsWorksitePositionManagerEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
dsWorksitePositionManagerEntityname.Dispose();
SqlCommand _sqlCommand;
//This is Only For WorksitePositionManager Start
if (strWorksitePositionManagerEntityname == "WorksitePositionManager")
{
string _strSqlWorksitePositionManager = " select WorksitePositionManager.WorksitePositionManagerID as [WorksitePositionManagerID~0],";
_strSqlWorksitePositionManager += " WorksitePositionManager.RowName as [RowName~0],";
_strSqlWorksitePositionManager += " WorksitePositionManager.StartDate as [StartDate~0], ";
_strSqlWorksitePositionManager += " WorksitePositionManager.EndDate as [EndDate~0],";
_strSqlWorksitePositionManager += " WorksitePosition.Rowname as [RowName~76],";
_strSqlWorksitePositionManager += " (select Rowname from WorksitePosition ";
_strSqlWorksitePositionManager += " where WorksitePositionID= WorksitePositionManager.ManagerWspID) ";
_strSqlWorksitePositionManager += " as [ManagerWorkSitePosition~76~1] from WorksitePositionManager inner join WorksitePosition ";
_strSqlWorksitePositionManager += " on WorksitePositionManager.WorksitePositionID = WorksitePosition.WorksitePositionID ";
_sqlCommand = new SqlCommand(_strSqlWorksitePositionManager, _sqlConnection);
}
//This is Only For WorksitePositionManager End
else
{
_sqlCommand = new SqlCommand("BuildDynamicRowsQuerry", _sqlConnection);
_sqlCommand.CommandType = CommandType.StoredProcedure;
_sqlCommand.Parameters.Add("@EntityID", SqlDbType.Int).Value = _intEntityID;
}
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_sqlCommand.ExecuteNonQuery();
SqlDataAdapter _sqlAdapter = new SqlDataAdapter(_sqlCommand);
_sqlAdapter.Fill(dt);
_sqlConnection.Close();
string StrSqlTablePk = "SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (select EntityName from Entity where EntityID='" + _intEntityID + "'))";
DataSet dsPktable = new DataSet();
dsPktable = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlTablePk);
string strTablePKName = string.Empty;
strTablePKName = dsPktable.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
dsPktable.Clear();
dsPktable.Dispose();
RadGridRow.MasterTableView.DataKeyNames = new string[] { strTablePKName + "~0" };//as Column Name In stored procedure
for (int i = 0; i < dt.Columns.Count; i++)
{
ListItem Item = new ListItem(dt.Columns[i].ToString(), dt.Columns[i].ToString());
string[] arr = dt.Columns[i].ToString().Split('~'); // split the string's spaces
string strColumnName = arr[0].ToString();
string strChkColumnType = arr[1].ToString();
String strGridColumnName = Item.Text; ;
string StrEntityName = string.Empty;
string strPKName = string.Empty;
string strColName = string.Empty;
if (strChkColumnType != "0")//FOR FKEntityID CHECK
{
String strSqlEntityname = "select EntityName from Entity where EntityID='" + strChkColumnType + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
StrEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString().Replace("'", "''").Trim();
dsEntityname.Dispose();
string StrSqlColNameTEMP = "(SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = (Select EntityName From Entity Where EntityID = '" + strChkColumnType + "')) ) C WHERE cid = 2) ";
DataSet dsColName = new DataSet();
dsColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, StrSqlColNameTEMP);
strGridColumnName = dsColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim();
dsColName.Clear();
dsColName.Dispose();
DataSet dsPk = new DataSet();
DataSet dstColName = new DataSet();
string strSqlPk = " SELECT TOP 1 [NAME] FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ";
string strSqlColName = " SELECT [NAME] FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS cid, * FROM syscolumns WHERE ID = (SELECT ID FROM sysobjects WHERE TYPE = 'U' AND [NAME] = '" + StrEntityName + "') ) C WHERE cid = 2 ";
dsPk = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlPk);
strPKName = dsPk.Tables[0].Rows[0]["NAME"].ToString();
dsPk.Clear();
dsPk.Dispose();
dstColName = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlColName);
strColName = dstColName.Tables[0].Rows[0]["NAME"].ToString().Replace("'", "''").Trim(); ;
dstColName.Clear();
dstColName.Dispose();
}
if ((dt.Columns[i].DataType.ToString() == "System.String") || (dt.Columns[i].DataType.ToString() == "System.Int32"))
{
if (strChkColumnType != "0")//FOR FKEntityID CHECK
{
if (dt.Columns[i].ToString() != "ManagerWorkSitePosition~76~1")//This is for WorksitePositionManager
{
string templateColumnName = StrEntityName;
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyItemTemplate(StrEntityName + "MyItemTemplate" + i.ToString(), Item.Value.ToString());
templateColumn.EditItemTemplate = new MyEditTemplate(StrEntityName + "MyEditTemplate" + i.ToString(), StrEntityName, strPKName, strColName, Item.Value.ToString(), strColumnName);
RadGridRow.MasterTableView.Columns.Add(templateColumn);
templateColumn.HeaderText = templateColumnName;
templateColumn.UniqueName = strColumnName;
}
else
{
string templateColumnName = "ManagerWorkSitePositon";
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyItemTemplateManager(Item.Value.ToString());
templateColumn.EditItemTemplate = new MyEditTemplateManager(Item.Value.ToString());
RadGridRow.MasterTableView.Columns.Add(templateColumn);
templateColumn.HeaderText = templateColumnName;
templateColumn.UniqueName = strColumnName;
}
}
else
{
if (strColumnName != "FullName")
{
GridBoundColumn boundColumn = new GridBoundColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
if (strTablePKName == strColumnName)
{
boundColumn.ReadOnly = true;//To Hide Pk ID In Edit Form
}
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
}
}
else if (dt.Columns[i].DataType.ToString() == "System.Boolean")
{
GridCheckBoxColumn boundColumn = new GridCheckBoxColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
else if (dt.Columns[i].DataType.ToString() == "System.DateTime")
{
GridDateTimeColumn boundColumn = new GridDateTimeColumn();
boundColumn.HeaderText = strColumnName;
boundColumn.DataField = Item.Value;
boundColumn.UniqueName = strColumnName;
boundColumn.DataFormatString = "{0:d}";
RadGridRow.MasterTableView.Columns.Add(boundColumn);
}
}
RadGridRow.DataSource = dt;
dt.Dispose();
GridEditCommandColumn col = new GridEditCommandColumn();
RadGridRow.MasterTableView.Columns.Add(col);
col.ButtonType = GridButtonColumnType.ImageButton;
col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
col.CancelText = "Cancel";
col.EditText = "Edit";
col.UpdateText = "Update";
col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
GridButtonColumn BtnDelete = new GridButtonColumn();
BtnDelete.ButtonType = GridButtonColumnType.ImageButton;
RadGridRow.MasterTableView.Columns.Add(BtnDelete);
// BtnDelete.HeaderText="Delete";
BtnDelete.Text = "Delete";
BtnDelete.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
BtnDelete.ItemStyle.VerticalAlign = VerticalAlign.Middle;
BtnDelete.CommandName = "Delete";
BtnDelete.ConfirmDialogType = GridConfirmDialogType.RadWindow;
BtnDelete.ConfirmText = "Are You Sure to Delete This Record?";
BtnDelete.ConfirmTitle = "Delete";
RadGridRow.MasterTableView.Columns.FindByUniqueName(strTablePKName).Visible = false;
// RadGridRow.Columns[0].Visible = false;
RadGridRow.ClientSettings.Scrolling.AllowScroll = true;
RadGridRow.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(380);
RadGridRow.MasterTableView.EditMode = GridEditMode.EditForms;
// RadGridRow.MasterTableView.EditFormSettings.EditColumn.ButtonType = GridButtonColumnType.ImageButton;
RadGridRow.MasterTableView.EditFormSettings.EditColumn.InsertImageUrl = "../Admin/Update.gif";
RadGridRow.MasterTableView.EditFormSettings.EditColumn.UpdateImageUrl = "../Admin/Update.gif";
RadGridRow.AllowSorting = true;
//RadGridRow.AllowPaging = true;
//RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
//RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
//RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
//RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
//RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
//RadGridRow.PagerStyle.PagerTextFormat = "Displaying Items {2} to {3} of {5}.";
//RadGridRow.AllowPaging = true;
//RadGridRow.PagerStyle.FirstPageImageUrl = "PagingFirst.gif";
//RadGridRow.PagerStyle.LastPageImageUrl = "PagingLast.gif";
//RadGridRow.PagerStyle.NextPageImageUrl = "PagingNext.gif";
//RadGridRow.PagerStyle.PrevPageImageUrl = "PagingPrev.gif";
//RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
// RadGridRow.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric ;
// RadGridRow.PagerStyle.PagerTextFormat = "Side: {4} | Viser brukere {2} til {3} av totalt {5} " ;
// RadGridRow.PagerStyle.NextPagesToolTip = "Neste sider" ;
//RadGridRow.PagerStyle.NextPageToolTip = "Neste sider" ;
//RadGridRow.PagerStyle.PrevPagesToolTip = "Forrige sider";
//RadGridRow.PagerStyle.PrevPageToolTip = "Forrige side" ;
//RadGridRow.PagerStyle.NextPageText = "»" ;
//RadGridRow.PagerStyle.PrevPageText = "«" ;
//RadGridRow.PagerStyle.EnableSEOPaging = true ;
//RadGridRow.PagerStyle.SEOPagingQueryStringKey = "side";
RadGridRow.PageSize = pageCount;
RadGridRow.MasterTableView.PageSize = pageCount;
RadGridRow.MasterTableView.CommandItemSettings.RefreshText = "";
RadGridRow.MasterTableView.CommandItemSettings.AddNewRecordText = "Add New";
RadGridRow.Rebind();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Error . Reason: " + ex.Message));
}
}
#endregion End GridBind Event
#region Grid Need Source Event Here
protected void RadGridRow_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
}
#endregion End Grid Need Source Event
#region Grid Cancel Event Here
private void RadGridRow_CancelCommand(object source, GridCommandEventArgs e)
{
}
#endregion End Cancel Evente Event
#region Grid RadGridRow_ItemCreated Event Here
protected void RadGridRow_ItemCreated(object sender, GridItemEventArgs e)
{
}
#endregion End RadGridRow_ItemCreated Event
#region Grid UpdateCommand Event Here
private void RadGridRow_UpdateCommand(object source, GridCommandEventArgs e)
{
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
ArrayList arrayListWhPkColumn = new ArrayList();
ArrayList arrayListWhPkValues = new ArrayList();
ArrayList arrayListDTColumn = new ArrayList();
ArrayList arrayListDTValues = new ArrayList();
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
string editorText = "unknown";
object editorValue = null;
if (editor is GridTextColumnEditor)
{
if (editor is GridDateTimeColumnEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else if (editor is RadDatePickerEditorClass.RadDatePickerEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
if (editor is GridBoolColumnEditor)
{
editorText = (editor as GridBoolColumnEditor).Value.ToString();
editorValue = (editor as GridBoolColumnEditor).Value;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
}
}
string _strWithoutPKColName = string.Empty;
string _strWithoutPKColvalue = string.Empty;
for (int i = 1; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 2 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + ",";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i];
}
}
for (int i = 1; i < arrayListWhPkValues.Count; i++)
{
if (arrayListWhPkValues.Count != 2 && i < arrayListWhPkValues.Count - 1)
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i] + ",";
}
else
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i];
}
}
string strSqlWithtFk = " select * from Attribute where EntityID='" + _intEntityID + "' and (FkEntityid is not null and FkEntityid !=0) ";
DataTable dtColumnInfoWithFk = new DataTable();
dtColumnInfoWithFk = SqlHelper.GetDataTable(_sqlConnectionString, strSqlWithtFk);
ArrayList arrayListWithPkColumn = new ArrayList();
ArrayList arrayListWithPkValues = new ArrayList();
for (int i = 0; i < dtColumnInfoWithFk.Rows.Count; i++)
{
string _strColumnNameValue = string.Empty;
string _strColName = string.Empty;
_strColName = dtColumnInfoWithFk.Rows[i]["ColumnName"].ToString();
arrayListWithPkColumn.Add(_strColName);
string _strFkColID = dtColumnInfoWithFk.Rows[i]["FKEntityID"].ToString();
DataTable _dtTableName = new DataTable();
_dtTableName = SqlHelper.GetDataTable(_sqlConnectionString, "select EntityName From Entity where EntityID='" + _strFkColID + "'");
string _drpSelectedvalue = String.Empty;
if (_strEntityName != "WorksitePositionManager")
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
else
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = string.Empty;
if (i == 1)
{
_strTableName = "managerWorksitePosition"; //This is for WorksitePositionManager
}
else
{
_strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
}
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
}
_strWithoutPKColName = string.Empty;
for (int i = 0; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 1 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + "=" + arrayListWhPkValues[i].ToString() + " ,";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i].ToString() + "=" + arrayListWhPkValues[i].ToString();
}
}
string _strColNamePK = string.Empty;
for (int i = 0; i < arrayListWithPkColumn.Count; i++)
{
if (arrayListWithPkColumn.Count != 1 && i < arrayListWithPkColumn.Count - 1)
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i].ToString() + "=" + arrayListWithPkValues[i].ToString() + " ,";
}
else
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i].ToString() + "=" + arrayListWithPkValues[i].ToString() + "";
}
}
string _strSqlUpdateColumn = string.Empty;
string _strSqlUpdateColumnValues = string.Empty;
if (arrayListWithPkColumn.Count == 0 && arrayListWithPkValues.Count == 0)
{
_strSqlUpdateColumn = _strWithoutPKColName;
}
else
{
_strSqlUpdateColumn = _strWithoutPKColName + "," + _strColNamePK;
}
string _strPKColumnNameUpdate = editedItem.OwnerTableView.DataKeyNames[0].ToString();
string _strPKColumnNameValueUpdate = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex][_strPKColumnNameUpdate].ToString();
// string _strSqlUpdateQuery = "Update " + _strEntityName + " set " + _strSqlUpdateColumn + " where " + arrayListWhPkColumn[0].ToString() + "=" + arrayListWhPkValues[0].ToString() + " ";
string _strSqlUpdateQuery = "Update " + _strEntityName + " set " + _strSqlUpdateColumn + " where " + _strPKColumnNameUpdate.Replace("~0", "") + "='" + _strPKColumnNameValueUpdate + "' ";
SqlCommand _cmdUpdateDetails = new SqlCommand(_strSqlUpdateQuery, _sqlConnection);
for (int i = 0; i < arrayListDTColumn.Count; i++)
{
if (arrayListDTColumn.Count != 0 && arrayListDTValues.Count != 0)
{
_cmdUpdateDetails.Parameters.Add(arrayListDTColumn[i].ToString(), SqlDbType.DateTime).Value = arrayListDTValues[i].ToString();
}
}
try
{
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_cmdUpdateDetails.ExecuteNonQuery();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End UpdateCommand Event
#region Grid Insert Command Event Here
private void RadGridRow_InsertCommand(object source, GridCommandEventArgs e)
{
int _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
ArrayList arrayListWhPkColumn = new ArrayList();
ArrayList arrayListWhPkValues = new ArrayList();
ArrayList arrayListDTColumn = new ArrayList();
ArrayList arrayListDTValues = new ArrayList();
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
string editorText = "unknown";
object editorValue = null;
if (editor is GridTextColumnEditor)
{
if (editor is GridDateTimeColumnEditor )
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else if (editor is RadDatePickerEditorClass.RadDatePickerEditor)
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("@" + column.UniqueName);
arrayListDTColumn.Add("@" + column.UniqueName);
arrayListDTValues.Add(editorValue);
}
else
{
editorText = (editor as GridTextColumnEditor).Text;
editorValue = (editor as GridTextColumnEditor).Text;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
if (editor is GridBoolColumnEditor)
{
editorText = (editor as GridBoolColumnEditor).Value.ToString();
editorValue = (editor as GridBoolColumnEditor).Value;
arrayListWhPkColumn.Add(column.UniqueName);
arrayListWhPkValues.Add("'" + editorValue + "'");
}
}
}
}
string _strWithoutPKColName = string.Empty;
string _strWithoutPKColvalue = string.Empty;
for (int i = 0; i < arrayListWhPkColumn.Count; i++)
{
if (arrayListWhPkColumn.Count != 1 && i < arrayListWhPkColumn.Count - 1)
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i] + ",";
}
else
{
_strWithoutPKColName = _strWithoutPKColName + arrayListWhPkColumn[i];
}
}
for (int i = 0; i < arrayListWhPkValues.Count; i++)
{
if (arrayListWhPkValues.Count != 1 && i < arrayListWhPkValues.Count - 1)
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i] + ",";
}
else
{
_strWithoutPKColvalue = _strWithoutPKColvalue + arrayListWhPkValues[i];
}
}
string strSqlWithtFk = " select * from Attribute where EntityID='" + _intEntityID + "' and (FkEntityid is not null and FkEntityid !=0) ";
DataTable dtColumnInfoWithFk = new DataTable();
dtColumnInfoWithFk = SqlHelper.GetDataTable(_sqlConnectionString, strSqlWithtFk);
ArrayList arrayListWithPkColumn = new ArrayList();
ArrayList arrayListWithPkValues = new ArrayList();
for (int i = 0; i < dtColumnInfoWithFk.Rows.Count; i++)
{
string _strColumnNameValue = string.Empty;
string _strColName = string.Empty;
_strColName = dtColumnInfoWithFk.Rows[i]["ColumnName"].ToString();
arrayListWithPkColumn.Add(_strColName);
string _strFkColID = dtColumnInfoWithFk.Rows[i]["FKEntityID"].ToString();
DataTable _dtTableName = new DataTable();
_dtTableName = SqlHelper.GetDataTable(_sqlConnectionString, "select EntityName From Entity where EntityID='" + _strFkColID + "'");
string _drpSelectedvalue = String.Empty;
//This is for WorksitePositionManager
if (_strEntityName != "WorksitePositionManager")
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
//This is for WorksitePositionManager End
else
{
for (int j = 0; j < _dtTableName.Rows.Count; j++)
{
string _strTableName = string.Empty;
if (i == 1)
{
_strTableName = "managerWorksitePosition";
}
else
{
_strTableName = _dtTableName.Rows[j]["EntityName"].ToString().Replace("'", "''");
}
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
{
if (column is IGridEditableColumn)
{
IGridEditableColumn editableCol = (column as IGridEditableColumn);
if (editableCol.IsEditable)
{
IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
if (editor is GridTemplateColumnEditor)
{
TableCell cell = (editor as GridTemplateColumnEditor).ContainerControl as TableCell;
_drpSelectedvalue = (cell.FindControl(_strTableName) as RadComboBox).SelectedValue.ToString();
}
}
}
}
arrayListWithPkValues.Add("'" + _drpSelectedvalue + "'");
}
}
}
string _strColNamePK = string.Empty;
string _strColvaluePK = string.Empty;
for (int i = 0; i < arrayListWithPkColumn.Count; i++)
{
if (arrayListWithPkColumn.Count != 1 && i < arrayListWithPkColumn.Count - 1)
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i] + ",";
}
else
{
_strColNamePK = _strColNamePK + arrayListWithPkColumn[i];
}
}
for (int i = 0; i < arrayListWithPkValues.Count; i++)
{
if (arrayListWithPkValues.Count != 1 && i < arrayListWithPkValues.Count - 1)
{
_strColvaluePK = _strColvaluePK + arrayListWithPkValues[i] + ",";
}
else
{
_strColvaluePK = _strColvaluePK + arrayListWithPkValues[i];
}
}
string _strSqlInsertColumn = string.Empty;
string _strSqlInsertColumnValues = string.Empty;
if (arrayListWithPkColumn.Count == 0 && arrayListWithPkValues.Count == 0)
{
_strSqlInsertColumn = _strWithoutPKColName;
_strSqlInsertColumnValues = _strWithoutPKColvalue;
}
else
{
_strSqlInsertColumn = _strWithoutPKColName + "," + _strColNamePK;
_strSqlInsertColumnValues = _strWithoutPKColvalue + "," + _strColvaluePK;
}
string _strSqlInsertQuery = "Insert Into " + _strEntityName + "(" + _strSqlInsertColumn + ") values(" + _strSqlInsertColumnValues + ")";
SqlCommand _cmdInsertDetails = new SqlCommand(_strSqlInsertQuery, _sqlConnection);
for (int i = 0; i < arrayListDTColumn.Count; i++)
{
if (arrayListDTColumn.Count != 0 && arrayListDTValues.Count != 0)
{
_cmdInsertDetails.Parameters.Add(arrayListDTColumn[i].ToString(), SqlDbType.DateTime).Value = DateTime.Parse(arrayListDTValues[i].ToString()).ToShortDateString();
}
}
try
{
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
_cmdInsertDetails.ExecuteNonQuery();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End InsertCommand Event
#region MyEditTemplate Class Start Here
private class MyEditTemplate : ITemplate, IBindableTemplate
{
protected Label label;
protected RadComboBox combobox;
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
private string colname;
private string radComboID;
private string tempStrEntityName;
private string tempStrPKName;
private string tempStrColName;
private string tempStrDataCol;
private string TemplateColumnUniqueName;
public MyEditTemplate(string cName, string StrEntityName, string StrPKName, string StrColName, string StrDataCol, string ColumnUniqueName)
{
colname = cName;
radComboID = cName;
tempStrEntityName = StrEntityName;
tempStrPKName = StrPKName;
tempStrColName = StrColName;
tempStrDataCol = StrDataCol;
TemplateColumnUniqueName = ColumnUniqueName;
}
public void combobox_DataBinding(object sender, EventArgs e)
{
RadComboBox cc = (RadComboBox) sender;
cc.Skin = "DwtDemo";
cc.EnableEmbeddedSkins = false;
SqlDataSource cmd = new SqlDataSource();
cmd.ConnectionString = _sqlConnectionString;
cmd.SelectCommand = "select * from " + tempStrEntityName;
cc.DataSource = cmd;
cc.DataTextField = tempStrColName;
cc.DataValueField = tempStrPKName;
}
public void label_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
lblData.Visible = false;
try
{
GridEditFormItem container = (GridEditFormItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[tempStrDataCol].ToString();
if (label.Text.ToString() != "")
{
combobox.Items.FindItemByText(label.Text.ToString()).Selected = true;
}
}
catch (Exception ex)
{
// LogHelper.ErrorLog(Ex.Message.ToString(), FilePath);
}
}
public void InstantiateIn(System.Web.UI.Control container)
{
combobox = new RadComboBox();
combobox.ID = tempStrEntityName;
combobox.Skin = "DwtDemo";
combobox.EnableEmbeddedSkins = false;
// combobox.SkinID = "WebBlue";
combobox.DataBinding += new EventHandler(combobox_DataBinding);
container.Controls.Add(combobox);
label = new Label();
label.ID = "lbl" + tempStrEntityName;
label.DataBinding += new EventHandler(label_DataBinding);
container.Controls.Add(label);
}
public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
System.Collections.Specialized.OrderedDictionary od = new System.Collections.Specialized.OrderedDictionary();
return od;
}
}
#endregion MyEditTemplate Class End Here
//This is for WorksitePositionManager
#region MyEditTemplateManager Class Start Here
private class MyEditTemplateManager : ITemplate, IBindableTemplate
{
protected Label label;
protected RadComboBox combobox;
private string tempStrDataCol = string.Empty;
string _sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbhsConnectionString"].ToString();
public MyEditTemplateManager(string StrDataCol)
{
tempStrDataCol = StrDataCol;
}
public void combobox_DataBinding(object sender, EventArgs e)
{
RadComboBox cc = (RadComboBox) sender;
cc.Skin = "DwtDemo";
cc.EnableEmbeddedSkins = false;
SqlDataSource cmd = new SqlDataSource();
cmd.ConnectionString = _sqlConnectionString;
cmd.SelectCommand = "select * from WorkSitePosition";
cc.DataSource = cmd;
cc.DataTextField = "RowName";
cc.DataValueField = "WorksitePositionID";
}
public void label_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
lblData.Visible = false;
try
{
GridEditFormItem container = (GridEditFormItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[tempStrDataCol].ToString();
if (label.Text.ToString() != "")
{
combobox.Items.FindItemByText(label.Text.ToString()).Selected = true;
}
}
catch (Exception ex)
{
// LogHelper.ErrorLog(Ex.Message.ToString(), FilePath);
}
}
public void InstantiateIn(System.Web.UI.Control container)
{
combobox = new RadComboBox();
combobox.ID = "managerWorksitePosition";
combobox.Skin = "DwtDemo";
combobox.EnableEmbeddedSkins = false;
// combobox.SkinID = "WebBlue";
combobox.DataBinding += new EventHandler(combobox_DataBinding);
container.Controls.Add(combobox);
label = new Label();
label.ID = "lblmanagerWorksitePosition";
label.DataBinding += new EventHandler(label_DataBinding);
container.Controls.Add(label);
}
public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
{
System.Collections.Specialized.OrderedDictionary od = new System.Collections.Specialized.OrderedDictionary();
return od;
}
}
#endregion MyEditTemplate Class End Here
#region MyItemTemplate Class Start Here
private class MyItemTemplate : ITemplate
{
protected Label label;
private string colname;
private string MyItemTemplateLbl;
public MyItemTemplate(string cName, string lblValue)
{
colname = cName;
MyItemTemplateLbl = lblValue;
}
public void textBox_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
GridDataItem container = (GridDataItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[MyItemTemplateLbl].ToString();
}
public void InstantiateIn(System.Web.UI.Control container)
{
label = new Label();
label.DataBinding += new EventHandler(textBox_DataBinding);
// textBox.Text = txtBoxID;
// textBox.ID = txtBoxID;
container.Controls.Add(label);
}
}
#endregion MyItemTemplate Class End Here
//This is for WorksitePositionManager
#region MyItemTemplateMaNAGER Class Start Here
private class MyItemTemplateManager : ITemplate
{
protected Label label;
private string colname;
private string MyItemTemplateLbl;
public MyItemTemplateManager(string lblValue)
{
colname = "managerWorksitePosition";
MyItemTemplateLbl = lblValue;
}
public void textBox_DataBinding(object sender, EventArgs e)
{
Label lblData = (Label) sender;
GridDataItem container = (GridDataItem) lblData.NamingContainer;
lblData.Text = ((DataRowView) container.DataItem)[MyItemTemplateLbl].ToString();
}
public void InstantiateIn(System.Web.UI.Control container)
{
label = new Label();
label.DataBinding += new EventHandler(textBox_DataBinding);
// textBox.Text = txtBoxID;
// textBox.ID = txtBoxID;
container.Controls.Add(label);
}
}
#endregion MyItemTemplate Class End Here
#region RadRowsEntity_SelectedIndexChanged Event
#region RadRowsEntity_SelectedIndexChangedEvent Here
protected void RadRowsEntity_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
// RadGridRow.Controls.Clear();
// _intEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
DefineGrid();
}
#endregion
#endregion RadRowsEntity_SelectedIndexChanged Event End Here
#region Display Message For Exception handling Event
private void DisplayMessage(string text)
{
RadGridRow.Controls.Add(new LiteralControl(text));
}
#endregion Display Message For Exception handling Event End here
#region Grid PreRender Event
protected void RadGridRow_PreRender(object sender, EventArgs e)
{
//RadGridRow.Rebind();
}
#endregion Grid PreRender Event
#region Start Delete Event
private void RadGridRow_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
int _intDelEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
String strSqlEntityname = "select EntityName from Entity where EntityID='" + _intDelEntityID + "'";
DataSet dsEntityname = new DataSet();
dsEntityname = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, strSqlEntityname);
string _strEntityName = dsEntityname.Tables[0].Rows[0]["EntityName"].ToString();
dsEntityname.Dispose();
// editedItem.OwnerTableView.DataKeyNames[0].ToString()
string _strDataKeyName = e.Item.OwnerTableView.DataKeyNames[0].ToString();
string[] _strdataColumnName = _strDataKeyName.Split('~');
string _strDataKeyNameValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][_strDataKeyName].ToString();
try
{
// _sqlConnection.ConnectionString = _sqlConnectionString;
if (_sqlConnection.State.ToString() == "Closed")
{
_sqlConnection.Open();
}
SqlTransaction _transaction = _sqlConnection.BeginTransaction();
string _strsql = "";
_strsql = "BEGIN TRANSACTION";
_strsql += " DELETE From " + _strEntityName + " Where " + _strdataColumnName[0].ToString() + " = '" + _strDataKeyNameValue + "'";
_strsql += " IF @@ERROR <>0 ROLLBACK TRANSACTION ";
_strsql += " ELSE COMMIT TRANSACTION";
SqlCommand _cmdDeleteEntity = new SqlCommand(_strsql, _sqlConnection);
_cmdDeleteEntity.Transaction = _transaction;
_cmdDeleteEntity.ExecuteNonQuery();
_transaction.Commit();
_sqlConnection.Close();
DefineGrid();
}
catch (Exception ex)
{
LogHelper.ErrorLog(ex.Message.ToString(), FilePath);
RadGridRow.Controls.Add(new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));
e.Canceled = true;
}
}
#endregion End Delete Events
#region Start CreateColumnEditor Event
private void RadGridRow_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
{
int _intCreateColEntityID = Int32.Parse(RadRowsEntity.SelectedValue.ToString());
string _strSqlRadGridRow=" Select Entity.EntityID, sys.all_objects.Name AS EntityName,sys.all_columns.Name AS ColumnName, sys.types.Name AS DataType ";
_strSqlRadGridRow += " From sys.all_columns ";
_strSqlRadGridRow += " INNER JOIN sys.all_objects ON all_columns.object_id = sys.all_objects.object_id ";
_strSqlRadGridRow += " INNER JOIN sys.types ON sys.types.system_type_id = sys.all_columns.system_type_id ";
_strSqlRadGridRow += " INNER JOIN Entity On Entity.EntityName = sys.all_objects.Name ";
_strSqlRadGridRow += " WHERE sys.all_columns.NAME IN (SELECT ColumnName FROM Attribute WHERE EntityID IN (SELECT EntityID From Entity)) ";
_strSqlRadGridRow += " AND sys.types.name = 'DateTime' and EntityID ='" + _intCreateColEntityID + "'";
DataSet _dsDateTimeColumn = new DataSet();
_dsDateTimeColumn = SqlHelper.ExecuteDataset(_sqlConnection, CommandType.Text, _strSqlRadGridRow);
string strDateTimeColumnName = string.Empty;
for(int i=0;i<_dsDateTimeColumn.Tables[0].Rows.Count;i++)
{
strDateTimeColumnName = string.Empty;
strDateTimeColumnName = _dsDateTimeColumn.Tables[0].Rows[i]["ColumnName"].ToString().Trim().Replace("'","''");
if (e.Column.UniqueName.ToLower().Trim() == strDateTimeColumnName.ToLower())
{
e.ColumnEditor = new RadDatePickerEditorClass.RadDatePickerEditor();
}
}
_dsDateTimeColumn.Clear();
_dsDateTimeColumn.Dispose();
}
#endregion End CreateColumnEditor Events
protected void RadGridRow_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
if (e.Column is GridEditCommandColumn)
{
GridEditCommandColumn editcol = (GridEditCommandColumn)e.Column;
//editcol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton;
editcol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
editcol.ButtonType = GridButtonColumnType.ImageButton;
}
//if (e.Column is GridButtonColumn)
//{
// GridButtonColumn deletecol = (GridButtonColumn)e.Column;
// if (deletecol.UniqueName == "AutoGeneratedDeleteColumn")
// {
// deletecol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton;
// deletecol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
// }
//}
}
#region RadGridRow ItemCommand Event Here
protected void RadGridRow_ItemCommand(object source, GridCommandEventArgs e)
{
string str = e.CommandName.ToString();
if (e.CommandName == "Edit")
{
RadGridRow.MasterTableView.IsItemInserted = false;
}
else if (e.CommandName == "InitInsert")
{
RadGridRow.EditIndexes.Clear();
}
else if (e.CommandName == "RebindGrid")
{
RadGridRow.MasterTableView.Rebind();
}
}
#endregion End RadGridRow ItemCommand Section
#endregion End Dynamic Row All Events
0
vinod
Top achievements
Rank 1
answered on 13 Oct 2008, 09:23 AM
Edit Column Runtime added & changed GridButtonColumnType to ImageButton throws Error....