I am not sure why its complicated or maybe im misunderstanding.
I have a custom datasource.
I programmatically add columns and then on ItemDataBound, I get the currentItem and bind the values from the custom object (currentItem) to the columns in the current row being bound. Great.
But now, I want to retrieve the values (potentially modified values) on an "Update" Command.
So I have an OnItemCommand and it does fire.
However, when trying to retrieve the value, I only get an empty HTML space even though the value is there.
Any ideas where I am going wrong?
Full code:
I have a custom datasource.
I programmatically add columns and then on ItemDataBound, I get the currentItem and bind the values from the custom object (currentItem) to the columns in the current row being bound. Great.
But now, I want to retrieve the values (potentially modified values) on an "Update" Command.
So I have an OnItemCommand and it does fire.
However, when trying to retrieve the value, I only get an empty HTML space even though the value is there.
Any ideas where I am going wrong?
protected void radGridMenus_OnItemCommand(object sender, GridCommandEventArgs e)
{
GridDataItem currentRow = e.Item as GridDataItem;
if (currentRow != null)
{
switch (e.CommandName.ToLower().Trim())
{
case "update":
// currentRow["MenuID"].Value - here it is Not sure why?
break;
default:
break;
}
}
}
Full code:
protected void Page_Init(object sender, EventArgs e)
{
this.DoSetDefaultMenuColumns();
}
private void DoSetDefaultMenuColumns()
{
// lets create the columns.
GridBoundColumn menuIDColumn = new GridBoundColumn();
menuIDColumn.HeaderText = "Menu ID";
menuIDColumn.DataField = "MenuID";
GridBoundColumn menuNameColumn = new GridBoundColumn();
menuNameColumn.HeaderText = "Menu Name";
menuNameColumn.DataField = "MenuName";
GridDropDownColumn menuOrderColumn = new GridDropDownColumn();
menuOrderColumn.HeaderText = "Menu Order ID";
menuOrderColumn.DataField = "MenuOrderID";
GridDropDownColumn parentIDColumn = new GridDropDownColumn();
parentIDColumn.HeaderText = "Parent ID";
parentIDColumn.DataField = "ParentID";
GridCheckBoxColumn isAdminColumn = new GridCheckBoxColumn();
isAdminColumn.HeaderText = "Is Admin";
isAdminColumn.DataField = "IsAdmin";
GridBoundColumn pageURLColumn = new GridBoundColumn();
pageURLColumn.HeaderText = "Page URL";
pageURLColumn.DataField = "PageURL";
GridCheckBoxColumn employeeAccessColumn = new GridCheckBoxColumn();
employeeAccessColumn.HeaderText = "Employee Access";
employeeAccessColumn.DataField = "EmployeeAccess";
GridCheckBoxColumn customerAccessColumn = new GridCheckBoxColumn();
customerAccessColumn.HeaderText = "Customer Access";
customerAccessColumn.DataField = "CustomerAccess";
GridButtonColumn updateColumn = new GridButtonColumn();
updateColumn.ButtonType = GridButtonColumnType.LinkButton;
updateColumn.HeaderText = "Update";
updateColumn.Text = "Update Menu Item";
updateColumn.UniqueName = "UpdateMenuItem";
updateColumn.CommandName = "Update";
updateColumn.ItemStyle.ForeColor = Color.Blue;
this.radGridMenus.MasterTableView.Columns.Add(menuIDColumn);
this.radGridMenus.MasterTableView.Columns.Add(menuNameColumn);
this.radGridMenus.MasterTableView.Columns.Add(menuOrderColumn);
this.radGridMenus.MasterTableView.Columns.Add(parentIDColumn);
this.radGridMenus.MasterTableView.Columns.Add(pageURLColumn);
this.radGridMenus.MasterTableView.Columns.Add(isAdminColumn);
this.radGridMenus.MasterTableView.Columns.Add(employeeAccessColumn);
this.radGridMenus.MasterTableView.Columns.Add(customerAccessColumn);
this.radGridMenus.MasterTableView.Columns.Add(updateColumn);
}
protected void radGridMenus_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
this.radGridMenus.DataSource = this.CurrentMenuItemsView; // List<
T
>
}
}
protected void radGridMenus_OnItemCommand(object sender, GridCommandEventArgs e)
{
GridDataItem currentRow = e.Item as GridDataItem;
if (currentRow != null)
{
switch (e.CommandName.ToLower().Trim())
{
case "update":
break;
default:
break;
}
}
}
protected void radGridMenus_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem currentItem = e.Item as GridDataItem;
var currentMenu = currentItem.DataItem as MProSoftwareMenus;
if (currentMenu != null)
{
if (currentMenu.ParentID.HasValue)
{
currentItem["ParentID"].Text = currentMenu.ParentID.Value.ToString();
}
if (currentMenu.MenuOrderID.HasValue)
{
currentItem["MenuOrderID"].Text = currentMenu.MenuOrderID.Value.ToString();
}
((CheckBox)currentItem["IsAdmin"].Controls[0]).Checked = currentMenu.IsAdmin.GetValueOrDefault(false);
((LinkButton)currentItem["UpdateMenuItem"].Controls[0]).CommandArgument = currentMenu.MenuID.ToString();
}
}
}