This is a migrated thread and some comments may be shown as answers.

Changes in ItemDataBound not visible until refresh

7 Answers 368 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 2
Tim asked on 19 Oct 2011, 03:25 PM
I know I must be missing something. If I make changes to a datagriditem in the ItemDataBound event of the RadGrid the changes are not visible the first time the page loads, I don't see the changes to the DataItem until I refresh the grid via the CommandItem for refresh. I have verified that the ItemDataBound event is fired and the values that I am replacing do infact have the correct values.

background:
I have a class that creates the RadGrid. It is then instantiated and loaded into the .aspx page via the code behind for the .aspx. This is a master/detail datagrid if that makes any difference.

Update: I pulled up a grid with multiple entries and all but the first griditem was loaded correctly on the initial load. After a refresh the first item was correct.

protected void Page_Init(object source, EventArgs e)
{
    this.__activeBatchesRadGrid = ActiveBatchesRadGrid.GridDefinition("ActiveBatchesRadGrid");
    this.PlaceHolder1.Controls.Add(this.__activeBatchesRadGrid);
    this.__activeBatchesRadGrid.ItemDataBound += new GridItemEventHandler(ActiveBatchesRadGrid_ItemDataBound);
}
 
private void ActiveBatchesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem _dataItem = e.Item as GridDataItem;
    if (_dataItem == null) return;
 
    BatchStatusType _batchStatus = EnumUtils.GetValueFromName<BatchStatusType>(_dataItem["BatchStatusName"].Text);
 
    Dictionary<BatchStatusType, BatchStatusType> _batchStatusTypes =
        BatchTransitions.GetBatchStatusTransition(_batchStatus);
         
    GridButtonColumn _btnPromote =
        ((GridButtonColumn) this.__activeBatchesRadGrid.MasterTableView.GetColumn("MasterPromoteRecord"));
 
    GridButtonColumn _btnDelete =
        ((GridButtonColumn)this.__activeBatchesRadGrid.MasterTableView.GetColumn("MasterDeleteRecord"));
 
    foreach (KeyValuePair<BatchStatusType, BatchStatusType> _item in _batchStatusTypes)
    {
        _btnPromote.Text = _item.Value.ToString();
        _btnPromote.ConfirmText = string.Format("Are you sure you want to promote this batch to {0} status?",
                                               _item.Value);
 
        _btnDelete.Text = string.Format("Demote batch to {0} status.", _item.Key.ToString());
        _btnDelete.ConfirmText = string.Format("Are you sure you want to demote this batch to {0} status?",
                                              _item.Key);
    }
}

7 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 2
answered on 21 Oct 2011, 02:24 PM
bump! Anybody?
0
Iana Tsolova
Telerik team
answered on 24 Oct 2011, 09:32 AM
Hi Tim,

Can you elaborate on how is the grid bound and share the code for the programmatic creation for further check?

All the best,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tim
Top achievements
Rank 2
answered on 24 Oct 2011, 02:27 PM
Hey Iana,
It works as expected except for the first datarow in the RadGrid. Once a refresh is executed or selecting the open child table arrow,, then the first row corrects to the proper values.

Here is the Grid Class:

using System;
using System.Data;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
namespace MAAS.WebApplication.Controls
{
    public static class BatchRadGrid
    {
 
        internal static RadGrid GridDefinition(string id)
        {
            RadGrid _policyRadGrid = new RadGrid
                                         {
                                             ID = id,
                                             Width = Unit.Percentage(98),
                                             Height = Unit.Pixel(460),
                                             PageSize = 10,
                                             AllowPaging = true,
                                             EnableAjaxSkinRendering = true,
                                             AllowSorting = true,
                                             AutoGenerateColumns = false,
                                             ShowStatusBar = true,
                                             GridLines = GridLines.None,
                                             AutoGenerateEditColumn = false,
                                             AutoGenerateDeleteColumn = false,
                                             ExportSettings =
                                                 {
                                                     HideStructureColumns = true,
                                                     ExportOnlyData = true,
                                                     IgnorePaging = true,
                                                     //OpenInNewWindow = true
                                                 },
                                             HeaderContextMenu =
                                                 {
                                                     Enabled = true,
                                                     CssClass = "GridContextMenu GridContextMenu_Web20"
                                                 },
                                             PagerStyle = {Mode = GridPagerMode.NextPrevNumericAndAdvanced},
                                             ClientSettings =
                                                 {
                                                     Scrolling = {AllowScroll = true, UseStaticHeaders = true},
                                                     Selecting = {AllowRowSelect = true},
                                                     AllowExpandCollapse = true,
                                                     ClientEvents = {OnRowDblClick = "RowDblClicked"}
 
                                                 },
                                             FilterMenu = {EnableImageSprites = false},
                                             MasterTableView =
                                                 {
                                                     PageSize = 10,
                                                     CommandItemDisplay = GridCommandItemDisplay.Top,
                                                     CommandItemSettings =
                                                         {
                                                             ShowExportToExcelButton = false,
                                                             AddNewRecordText = "Add New Batch"
                                                         },
                                                     EnableHeaderContextMenu = true,
                                                     HorizontalAlign = HorizontalAlign.NotSet,
                                                     EditFormSettings =
                                                         {
                                                             FormCaptionStyle = {CssClass = "EditFormHeader"},
                                                             ColumnNumber = 3,
                                                             CaptionDataField = "BatchID",
                                                             CaptionFormatString = "Edit properties of Item {0}",
                                                             InsertCaption = "New Batch",
                                                             FormTableItemStyle = {Wrap = false},
                                                             FormMainTableStyle =
                                                                 {
                                                                     BackColor = Color.FromArgb(222, 222, 214),
                                                                     CellPadding = 3,
                                                                     CellSpacing = 0,
                                                                     GridLines = GridLines.None,
                                                                     Width = Unit.Percentage(43)
                                                                 },
                                                             FormTableStyle =
                                                                 {
                                                                     BackColor = Color.FromArgb(222, 222, 214),
                                                                     CellPadding = 2,
                                                                     CellSpacing = 0,
                                                                     Height = Unit.Percentage(100)
                                                                 },
                                                             FormTableAlternatingItemStyle = {Wrap = false},
                                                             //EditColumn =
                                                             //    {
                                                             //        ButtonType = GridButtonColumnType.ImageButton,
                                                             //        InsertText = "Insert Record",
                                                             //        UpdateText = "Update Record",
                                                             //        UniqueName = "MasterFormEditRecord",
                                                             //        CancelText = "Cancel Edit",
                                                             //        FilterControlAltText =
                                                             //            "Filter EditCommandColumn column"
                                                             //    },
                                                             FormTableButtonRowStyle =
                                                                 {
                                                                     HorizontalAlign = HorizontalAlign.Right,
                                                                     CssClass = "EditFormButtonRow"
                                                                 },
                                                         },
                                                     HierarchyLoadMode = GridChildLoadMode.ServerBind,
                                                     DataKeyNames = new string[] {"BatchID"},
                                                     EditMode = GridEditMode.PopUp,
                                                 },
                                         };
 
            //Add Edit Column
            GridEditCommandColumn _masterGridEditCommandColumn = new GridEditCommandColumn
                                                                     {
                                                                         ButtonType = GridButtonColumnType.ImageButton,
                                                                         HeaderText = "",
                                                                         UniqueName = "MasterEditRecord",
                                                                         HeaderStyle = {Width = Unit.Pixel(20)},
                                                                         ItemStyle = {Width = Unit.Pixel(20)}
                                                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterGridEditCommandColumn);
 
            //Add Delete Column
            GridButtonColumn _masterDeleteCommandColumn = new GridButtonColumn
                                                              {
                                                                  ConfirmText = "Confirm",
                                                                  ConfirmDialogType = GridConfirmDialogType.RadWindow,
                                                                  ButtonType = GridButtonColumnType.ImageButton,
                                                                  HeaderText = "",
                                                                  ConfirmTitle = "Delete",
                                                                  CommandName = "Delete",
                                                                  Text = "Delete",
                                                                  UniqueName = "MasterDeleteRecord",
                                                                  HeaderStyle = {Width = Unit.Pixel(20)},
                                                                  ItemStyle =
                                                                      {
                                                                          HorizontalAlign = HorizontalAlign.Center,
                                                                          Width = Unit.Pixel(20)
                                                                      }
                                                              };
 
            _policyRadGrid.MasterTableView.Columns.Add(_masterDeleteCommandColumn);
 
            GridBoundColumn _masterBoundColumn = new GridBoundColumn
                                                     {
                                                         DataField = "BatchID",
                                                         HeaderText = "Batch ID",
                                                         UniqueName = "BatchID",
                                                         HeaderStyle = {Width = Unit.Pixel(50)},
                                                         ItemStyle = {Width = Unit.Pixel(50)},
                                                         ReadOnly = true,
                                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
 
            _masterBoundColumn = new GridBoundColumn
                                     {
                                         DataField = "AccountingPeriodID",
                                         HeaderText = "Accounting Period",
                                         UniqueName = "AccountingPeriodID",
                                         HeaderStyle = {Width = Unit.Pixel(130)},
                                         ItemStyle = {Width = Unit.Pixel(130)},
                                         ReadOnly = true,
                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
            _masterBoundColumn = new GridBoundColumn
                                     {
                                         DataField = "BatchName",
                                         HeaderText = "Batch Name",
                                         UniqueName = "BatchName",
                                         HeaderStyle = {Width = Unit.Pixel(200)},
                                         ItemStyle = {Width = Unit.Pixel(200)},
                                         ReadOnly = true,
                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
 
            _masterBoundColumn = new GridBoundColumn
                                     {
                                         DataField = "BatchStatusName",
                                         HeaderText = "Batch Status",
                                         UniqueName = "BatchStatusName",
                                         HeaderStyle = {Width = Unit.Pixel(80)},
                                         ItemStyle = {Width = Unit.Pixel(80)},
                                         ReadOnly = true,
                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
 
            //_masterBoundColumn = new GridBoundColumn
            //                         {
            //                             DataField = "StatusDescription",
            //                             HeaderText = "Status Description",
            //                             UniqueName = "StatusDescription",
            //                             HeaderStyle = { Width = Unit.Pixel(100) },
            //                             ItemStyle = { Width = Unit.Pixel(100) },
            //                             ReadOnly = true,
            //                         };
            //_policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
 
            _masterBoundColumn = new GridBoundColumn
                                     {
                                         DataField = "BatchDescription",
                                         HeaderText = "Batch Description",
                                         UniqueName = "BatchDescription",
                                         HeaderStyle = {Width = Unit.Percentage(100)},
                                         ItemStyle = {Width = Unit.Percentage(100)},
                                     };
            _policyRadGrid.MasterTableView.Columns.Add(_masterBoundColumn);
 
 
            GridButtonColumn _masterPromoteCommandColumn = new GridButtonColumn
                                                               {
                                                                   ConfirmText = "",
                                                                   ConfirmDialogType = GridConfirmDialogType.RadWindow,
                                                                   ButtonType = GridButtonColumnType.PushButton,
                                                                   HeaderText = "",
                                                                   ConfirmTitle = "Promote Batch",
                                                                   CommandName = "Promote",
                                                                   Text = "Promote",
                                                                   UniqueName = "MasterPromoteRecord",
                                                                   HeaderStyle = {Width = Unit.Pixel(80)},
                                                                   ItemStyle =
                                                                       {
                                                                           HorizontalAlign = HorizontalAlign.Center,
                                                                           Width = Unit.Pixel(100)
                                                                       }
                                                               };
 
            _policyRadGrid.MasterTableView.Columns.Add(_masterPromoteCommandColumn);
 
 
            // (II in hierarchy level) Detail table - Manual Adjustments of the Batch
 
            GridTableView _batchAdjustments = new GridTableView(_policyRadGrid)
                                                  {
                                                      ID = string.Format("{0}_ChildGrid", id),
                                                      Name = string.Format("{0}_ChildGrid", id),
                                                      DataMember = "Policy",
                                                      AutoGenerateColumns = false,
                                                      Width = Unit.Percentage(100),
                                                      PageSize = 10,
                                                      BackColor = Color.FromArgb(198, 203, 214),
                                                      CommandItemDisplay = GridCommandItemDisplay.Top,
                                                      //CommandItemTemplate = new MyCommandItemTemplate(),
                                                      CommandItemSettings =
                                                          {
                                                              ShowExportToExcelButton = true,
                                                              AddNewRecordText = "Add New Adjustment",
 
                                                          },
                                                      EnableHeaderContextMenu = true,
                                                      HorizontalAlign = HorizontalAlign.NotSet,
                                                      EditFormSettings =
                                                          {
                                                              //UserControlName = "Controls/AdjustmentWorkFlow/NewAdjustment.ascx",
                                                              //EditFormType = GridEditFormType.WebUserControl,
                                                              //PopUpSettings =
                                                              //    {
                                                              //        Width = Unit.Pixel(1090),
                                                              //    },
 
                                                              //FormCaptionStyle = {CssClass = "EditFormHeader"},
                                                              //ColumnNumber = 4,
                                                              ////CaptionDataField = "Policy",
                                                              ////CaptionFormatString = "Edit properties of Item {0}",
                                                              ////InsertCaption = "New Policy",
                                                              //FormTableItemStyle = {Wrap = false},
                                                              //FormMainTableStyle =
                                                              //    {
                                                              //        BackColor = Color.FromArgb(222, 222, 214),
                                                              //        CellPadding = 3,
                                                              //        CellSpacing = 0,
                                                              //        GridLines = GridLines.None,
                                                              //        Width = Unit.Percentage(50)
                                                              //    },
                                                              //FormTableStyle =
                                                              //    {
                                                              //        BackColor = Color.FromArgb(222, 222, 214),
                                                              //        CellPadding = 2,
                                                              //        CellSpacing = 0,
                                                              //        Height = Unit.Percentage(100)
                                                              //    },
                                                              //FormTableAlternatingItemStyle = {Wrap = false},
                                                              EditColumn =
                                                                  {
                                                                      //        ButtonType = GridButtonColumnType.ImageButton,
                                                                      //        InsertText = "Insert Record",
                                                                      //        UpdateText = "Update Record",
                                                                      UniqueName = "EditRecord",
                                                                      //        CancelText = "Cancel Edit",
                                                                      //        FilterControlAltText =
                                                                      //            "Filter EditCommandColumn column"
                                                                  },
                                                              //FormTableButtonRowStyle =
                                                              //    {
                                                              //        HorizontalAlign = HorizontalAlign.Right,
                                                              //        CssClass = "EditFormButtonRow"
                                                              //    },
                                                          },
                                                      HierarchyLoadMode = GridChildLoadMode.ServerOnDemand,
                                                      EditMode = GridEditMode.PopUp,
                                                  };
 
            GridRelationFields _relationFields = new GridRelationFields
                                                     {
                                                         MasterKeyField = "BatchID",
                                                         DetailKeyField = "ManualAdjustmentBatchId"
                                                     };
            _batchAdjustments.ParentTableRelation.Add(_relationFields);
 
            _policyRadGrid.MasterTableView.DetailTables.Add(_batchAdjustments);
 
 
            //Add Edit Column
            GridEditCommandColumn _gridEditCommandColumn = new GridEditCommandColumn
                                                               {
                                                                   ButtonType = GridButtonColumnType.ImageButton,
                                                                   HeaderText = "",
                                                                   UniqueName = "PolicyEditRecord",
                                                                   HeaderStyle = {Width = Unit.Pixel(33)},
                                                                   ItemStyle = {Width = Unit.Pixel(33)}
                                                               };
            _batchAdjustments.Columns.Add(_gridEditCommandColumn);
 
            //Add Delete Column
            GridButtonColumn _deleteCommandColumn = new GridButtonColumn
                                                        {
                                                            ConfirmText = "Delete this item?",
                                                            ConfirmDialogType = GridConfirmDialogType.RadWindow,
                                                            ButtonType = GridButtonColumnType.ImageButton,
                                                            ConfirmTitle = "Delete",
                                                            CommandName = "Delete",
                                                            Text = "Delete",
                                                            UniqueName = "PolicyDeleteRecord",
                                                            HeaderStyle = {Width = Unit.Pixel(33)},
                                                            ItemStyle =
                                                                {
                                                                    HorizontalAlign = HorizontalAlign.Center,
                                                                    Width = Unit.Pixel(33)
                                                                },
                                                        };
 
 
            _batchAdjustments.Columns.Add(_deleteCommandColumn);
 
 
            //Add columns
            GridBoundColumn _boundColumn = new GridBoundColumn
                                               {
                                                   DataField = "OriginatingSystemCode",
                                                   HeaderText = "Originating System Code",
                                                   UniqueName = "OriginatingSystemCode",
                                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                                   ItemStyle = {Width = Unit.Pixel(100)},
                                                   Visible = false,
                                                   ReadOnly = true,
                                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "PolicyNumber",
                                   HeaderText = "Policy Number",
                                   UniqueName = "PolicyNumber",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 0,
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "PolicyVersion",
                                   HeaderText = "Policy Version",
                                   UniqueName = "PolicyVersion",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 1,
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "InternalLegalEntityCode",
                                   HeaderText = "Internal Legal Entity Code",
                                   UniqueName = "InternalLegalEntityCode",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 2,
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "ProductLine2Name",
                                   HeaderText = "Product Line 2 Name",
                                   UniqueName = "ProductLine2Name",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 3
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "DirectAssumedCededCode",
                                   HeaderText = "Direct Assumed Ceded Code",
                                   UniqueName = "DirectAssumedCededCode",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 0,
 
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "PolicyTransactionTypeCode",
                                   HeaderText = "Policy Transaction Type Code",
                                   UniqueName = "PolicyTransactionTypeCode",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 1
                               };
 
        _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "FinancialAmount",
                                     HeaderText = "Financial Amount",
                                     UniqueName = "FinancialAmount",
                                     HeaderStyle = {Width = Unit.Pixel(100)},
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 2,
                                     DataFormatString = "{0:C}"
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            GridDateTimeColumn _bounddtColumn = new GridDateTimeColumn
            {
                                   DataField = "PolicyEffectiveDate",
                                   HeaderText = "Policy Effective Date",
                                   UniqueName = "PolicyEffectiveDate",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 3,
                                   DataFormatString = "{0:M/d/yyyy}",
                               };
            _batchAdjustments.Columns.Add(_bounddtColumn);
 
            _boundColumn = new GridBoundColumn
                                      {
                                          DataField = "CoverageCode",
                                          HeaderText = "Coverage Code",
                                          UniqueName = "CoverageCode",
                                          HeaderStyle = { Width = Unit.Pixel(100) },
                                          ItemStyle = {Width = Unit.Pixel(100)},
                                          Visible = false,
                                          ReadOnly = true,
                                      };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "AnnualStatementLineNAICCode",
                                     HeaderText = "Annual Statement Line NAIC Code",
                                     UniqueName = "AnnualStatementLineNAICCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "InwardAssumingCompanyCode",
                                     HeaderText = "Inward Assuming Company Code",
                                     UniqueName = "InwardAssumingCompanyCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 1,
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                               {
                                   DataField = "ProducerCode",
                                   HeaderText = "Producer Code",
                                   UniqueName = "ProducerCode",
                                   HeaderStyle = {Width = Unit.Pixel(100)},
                                   ItemStyle = {Width = Unit.Pixel(100)},
                                   EditFormColumnIndex = 2,
                                   DataFormatString = "{0:MM/dd/yyyy}",
                               };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "LegacyProgramCode",
                                     HeaderText = "Legacy Program Code",
                                     UniqueName = "LegacyProgramCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 3,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "FinancialRiskISOCountrySubdivisionCode",
                                     HeaderText = "Financial Risk ISO Country Subdivision Code",
                                     UniqueName = "FinancialRiskISOCountrySubdivisionCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "LineOfBusinessCode",
                                     HeaderText = "Line Of Business  Code",
                                     UniqueName = "LineOfBusinessCodeb",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 2,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "SublineCode",
                                     HeaderText = "Subline  Code",
                                     UniqueName = "SublineCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 3,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "RatingClassCode",
                                     HeaderText = "Rating Class  Code",
                                     UniqueName = "RatingClassCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "CoverageTriggerCode",
                                     HeaderText = "Coverage Trigger Code",
                                     UniqueName = "CoverageTriggerCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 1,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "RegionCode",
                                     HeaderText = "Region Code",
                                     UniqueName = "RegionCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 2,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "LegacyAccountingUnitCode",
                                     HeaderText = "Legacy Accounting Unit Code",
                                     UniqueName = "LegacyAccountingUnitCode",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 3,
 
                                 };
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _bounddtColumn = new GridDateTimeColumn
                                 {
                                     DataField = "PremiumFinancialEffectiveFromDate",
                                     HeaderText = "Premium Financial Effective From Date",
                                     UniqueName = "PremiumFinancialEffectiveFromDate",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                     DataFormatString = "{0:M/d/yyyy}",
                                 };
            _batchAdjustments.Columns.Add(_bounddtColumn);
 
            _bounddtColumn = new GridDateTimeColumn
                                 {
                                     DataField = "PremiumFinancialEffectiveToDate",
                                     HeaderText = "Premium Financial Effective To Date",
                                     UniqueName = "PremiumFinancialEffectivetoDate",
                                     HeaderStyle = {Width = Unit.Pixel(100)},
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                     DataFormatString = "{0:M/d/yyyy}",
 
                                 };
            _batchAdjustments.Columns.Add(_bounddtColumn);
 
            _bounddtColumn = new GridDateTimeColumn
                                 {
                                     DataField = "CoverageEffectiveDate",
                                     HeaderText = "Coverage Effective Date",
                                     UniqueName = "CoverageEffectiveDate",
                                     HeaderStyle = { Width = Unit.Pixel(100) },
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                     DataFormatString = "{0:M/d/yyyy}",
                                 };
 
            _batchAdjustments.Columns.Add(_bounddtColumn);
 
            _bounddtColumn = new GridDateTimeColumn
                                 {
                                     DataField = "CoverageExpirationDate",
                                     HeaderText = "Coverage Expiration Date",
                                     UniqueName = "CoverageExpirationDate",
                                     HeaderStyle = {Width = Unit.Pixel(100)},
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                     DataFormatString = "{0:M/d/yyyy}",
                                 };
 
            _batchAdjustments.Columns.Add(_bounddtColumn);
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "PolicyClaimManualAdjustmentTypeName",
                                     HeaderText = "Manual Adjustment Type Name",
                                     UniqueName = "PolicyClaimManualAdjustmentTypeName",
                                     HeaderStyle = {Width = Unit.Pixel(100)},
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                 };
 
            _batchAdjustments.Columns.Add(_boundColumn);
 
            _boundColumn = new GridBoundColumn
                                 {
                                     DataField = "AutoGenerated",
                                     HeaderText = "Auto-Generated",
                                     UniqueName = "AutoGenerated",
                                     HeaderStyle = {Width = Unit.Pixel(100)},
                                     ItemStyle = {Width = Unit.Pixel(100)},
                                     EditFormColumnIndex = 0,
                                 };
 
            _batchAdjustments.Columns.Add(_boundColumn);
            return _policyRadGrid;
        }
    }
}

Here is the Control that instantiates the Grid Class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using MAAS.BusinessEntities;
using MAAS.Common;
using Telerik.Web.UI;
 
namespace MAAS.WebApplication.Controls
{
    public partial class ActiveBatches : MAASBaseUserControl
    {
        private RadGrid __activeBatchesRadGrid = new RadGrid();
        protected void Page_Init(object source, EventArgs e)
        { }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            this.__activeBatchesRadGrid = BatchRadGrid.GridDefinition("ActiveBatchesRadGrid");
            this.PlaceHolder1.Controls.Add(this.__activeBatchesRadGrid);
 
            this.__activeBatchesRadGrid.InsertCommand += new GridCommandEventHandler(ActiveBatchesRadGrid_InsertCommand);
            this.__activeBatchesRadGrid.UpdateCommand += new GridCommandEventHandler(ActiveBatchesRadGrid_UpdateCommand);
            this.__activeBatchesRadGrid.DeleteCommand += new GridCommandEventHandler(ActiveBatchesRadGrid_DeleteCommand);
 
            this.__activeBatchesRadGrid.ItemCreated += new GridItemEventHandler(ActiveBatchesRadGrid_ItemCreated);
            this.__activeBatchesRadGrid.ItemCommand += new GridCommandEventHandler(ActiveBatchesRadGrid_ItemCommand);
            this.__activeBatchesRadGrid.ItemInserted += new GridInsertedEventHandler(ActiveBatchesRadGrid_ItemInserted);
            this.__activeBatchesRadGrid.ItemUpdated += new GridUpdatedEventHandler(ActiveBatchesRadGrid_ItemUpdated);
            this.__activeBatchesRadGrid.ItemDataBound += new GridItemEventHandler(ActiveBatchesRadGrid_ItemDataBound);
 
            this.__activeBatchesRadGrid.NeedDataSource += new GridNeedDataSourceEventHandler(ActiveBatchesRadGrid_NeedDataSource);
            this.__activeBatchesRadGrid.DetailTableDataBind += new GridDetailTableDataBindEventHandler(ActiveBatchesRadGrid_DetailTableDataBind);
 
            RadAjaxManager.GetCurrent(this.Page).ClientEvents.OnRequestStart = "onRequestStart";
        }
 
        private void ActiveBatchesRadGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                GridNestedViewItem _nestedItem = e.Item as GridNestedViewItem;
                _nestedItem.NestedViewCell.PreRender += new EventHandler(NestedViewCell_PreRender);
                RadGrid _childGrid = (RadGrid)e.Item.OwnerTableView.FindControl("ActiveBatchesRadGrid_ChildGrid");
            }
            if (e.Item is GridCommandItem)
            {
                string _ownerId = e.Item.OwnerTableView.DataSource.ToString();
                if (_ownerId.IndexOf("AdjustmentList") != -1)
                {
                    Button addNewRecordButton = (Button)e.Item.FindControl("AddNewRecordButton");
                    LinkButton initInsertButton = (LinkButton)e.Item.FindControl("InitInsertButton");
                    addNewRecordButton.OnClientClick = "OpenAddAdjustmentPage();return false;";
                    initInsertButton.OnClientClick = "OpenAddAdjustmentPage();return false";
                }
            }
        }
 
        private void ActiveBatchesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            GridDataItem _dataItem = e.Item as GridDataItem;
            if (_dataItem == null) return;
            if (_dataItem.KeyValues == "{}") { return; }
 
            Dictionary<String, String> _batchStatusTypes =
                BatchTransitions.GetBatchStatusTransition(
                    EnumUtils.GetValueFromName<BatchStatusType>(_dataItem["BatchStatusName"].Text));
 
            GridButtonColumn _btnPromote = ((GridButtonColumn)this.__activeBatchesRadGrid.MasterTableView.GetColumn("MasterPromoteRecord"));
            GridButtonColumn _btnDelete = ((GridButtonColumn)this.__activeBatchesRadGrid.MasterTableView.GetColumn("MasterDeleteRecord"));
            int x = 0;
 
            foreach (KeyValuePair<String, String> _kvp in _batchStatusTypes)
            {
                _btnDelete.Text = string.Format("{0} batch", _kvp.Key);
                _btnPromote.Text = _kvp.Value;
                x++;
 
                if (x != 1) continue;
                _btnDelete.ConfirmText = string.Format("Are you sure you want to demote this batch to {0} status?", _kvp.Key);
                _btnPromote.ConfirmText = string.Format("Are you sure you want to promote this batch to {0} status?", _kvp.Value);
            }
        }
 
        private void ActiveBatchesRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
             this.__activeBatchesRadGrid.DataSource = BatchAPI.GetBatches(UserInfo.LogonName, ManualAdjustmentTypeCode, PolicyClaimManualAdjustmentCode, GrossCededCode, BatchStatusType.Entered);
        }
 
        private void ActiveBatchesRadGrid_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem _dataItem = e.DetailTableView.ParentItem;
            e.DetailTableView.DataSource = BatchAPI.BatchAdjustments(Convert.ToInt32(_dataItem.GetDataKeyValue("BatchID").ToString()), PolicyClaimManualAdjustmentCode);
        }
 
        private void ActiveBatchesRadGrid_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                GridTableView _gridTableView = (GridTableView)e.Item.OwnerTableView;
            }
            if (e.CommandName == RadGrid.ExportToExcelCommandName)
            {
                GridTableView _gridTableView = (GridTableView)e.Item.OwnerTableView;
                _gridTableView.GetColumn("PolicyEditRecord").Visible = false;
                _gridTableView.GetColumn("PolicyDeleteRecord").Visible = false;
                this.__activeBatchesRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
            }
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem _selectedRow = e.Item as GridDataItem;
                    BatchId = (int)_selectedRow.GetDataKeyValue("BatchID");
                }
            }
            if (e.CommandName == "Promote")
            {
                PromoteBatch(e);
            }
        }
 
        private void PromoteBatch(GridCommandEventArgs e)
        {
            GridEditableItem _item = e.Item as GridEditableItem;
            if (null == _item) { return; }
 
            try
            {
                BatchAPI.PromoteBatch((int)_item.GetDataKeyValue("BatchID"), UserInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.__activeBatchesRadGrid.DataBind();
            }
        }
 
        private void ActiveBatchesRadGrid_ItemUpdated(object source, GridUpdatedEventArgs e)
        {
            GridEditableItem _item = (GridEditableItem)e.Item;
            String _id = _item.GetDataKeyValue("ProductID").ToString();
 
            if (e.Exception == null) {return;}
 
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
        }
 
        private void ActiveBatchesRadGrid_ItemInserted(object source, GridInsertedEventArgs e)
        {
            if (e.Exception == null) {return;}
            e.ExceptionHandled = true;
        }
 
        private void ActiveBatchesRadGrid_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem _item = e.Item as GridEditableItem;
            if (null == _item) { return; }
            UpdateNewBatch(_item);
        }
 
        private void UpdateNewBatch(GridEditableItem item)
        {
            try
            {
                Hashtable _values = new Hashtable();
                item.ExtractValues(_values);
                Batch _batch = new Batch();
                _batch.BatchID = (int)item.GetDataKeyValue("BatchID");
                _batch.UserName = UserInfo.LogonName;
                item.UpdateValues(_batch);
 
                BatchAPI.UpdateBatch(_batch);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.__activeBatchesRadGrid.DataBind();
            }
        }
 
        private void ActiveBatchesRadGrid_InsertCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem _item = e.Item as GridEditableItem;
            if (null == _item) { return; }
            InsertNewBatch(_item);
        }
 
        private void InsertNewBatch(GridEditableItem item)
        {
            try
            {
                Hashtable _values = new Hashtable();
                item.ExtractValues(_values);
                Batch _batch = new Batch();
                item.UpdateValues(_batch);
                _batch.UserName = UserInfo.LogonName;
                _batch.BatchName = String.Empty; // The SP creates the Batch Name Automatically for this process
                _batch.AccountingPeriodID = AccountingPeriod.AccountingPeriodID;
                _batch.SystemBatchIndicator = "N";
                _batch.GrossCededCode = GrossCededCode;
                _batch.PolicyClaimManualAdjustmentTypeCode = PolicyClaimManualAdjustmentCode;
                _batch.ManualAdjustmentTypeCode = ManualAdjustmentTypeCode;
                _batch.FileName = String.Empty;
                BatchAPI.InsertBatch(_batch);
 
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                __activeBatchesRadGrid.DataBind();
            }
 
        }
 
        private void ActiveBatchesRadGrid_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DemoteBatch(e);
        }
 
        private void DemoteBatch(GridCommandEventArgs e)
        {
            GridEditableItem _item = e.Item as GridEditableItem;
            if (null == _item) { return; }
 
            try
            {
                BatchAPI.DemoteBatch((int)_item.GetDataKeyValue("BatchID"), UserInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                __activeBatchesRadGrid.DataBind();
            }
        }   
    }
}



0
Iana Tsolova
Telerik team
answered on 26 Oct 2011, 02:33 PM
Hi Tim,

I reviewed your code and here are my findings:
The settings you make to the grid columns will be applied after the grid is rebound. And I assume that is why it is not working for the first item and is fine for the next items.
Also, note that the settings for a column a global for all rows. So no matter you are changing the ConfirmText for the column on each ItemDataBound, only the last setting will be applied. Therefore in order to achieve your goal, and display different confirm text for each row, I would suggest that you implement the confirmation in a custom manner. For instance by handling the delete button client click, or using a GridTemplateColumn with Button in the ItemTemplate. Or by handling the client-side OnCommand event and there show the confirm box. And if the user selected Cancel, then cancel the delete command in the OnCommand event handler.

Best wishes,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tim
Top achievements
Rank 2
answered on 26 Oct 2011, 03:03 PM
Hi Iana,
Actually for my implementation this will work fine. I am working with only one Grid Class but each usercontrol that loads the data into that grid will be for a specific purpose. If a user is in an AD role for the application that will only allow them to 'submit items for approval' then only those records that are able to be submitted will be retrieved and loaded into the grid. If the user is an 'approver' role, then the grid will only retrieve and display records that are in a state to be approved thus the button for each row will be an 'approve' button. Having that in mind is there a way to get the first row to display properly without a refresh?

Tim
0
Iana Tsolova
Telerik team
answered on 26 Oct 2011, 03:30 PM
Hello Tim,

I am afraid I have no idea how this could be done without additional rebind. However, if you can recreate the scenario and the issue in a runnable sample and send it in a formal support ticket, I will forward it to our developers for further debugging so we see if we can find a suitable workaround for you.

All the best,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tim
Top achievements
Rank 2
answered on 28 Oct 2011, 03:16 PM
Hey Iana,
I thought I would post the solution I put together that takes care of this problem. I do however, still believe that the proper implementation that I originally posted should work. If it works for all items other than the first datagrid row then I believe there is a shortcoming in the control.

Attached is an image of the datagrid after initial loading. You will notice that all icons display correctly the first time and that the tooltip is correct on the first datarow. The other image displays the confirm box using the RadWindow with the correct dynamically generated message for the first datarow.

private void ActiveBatchesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem _dataItem = e.Item as GridDataItem;
    if (_dataItem == null) return;
    if (_dataItem.KeyValues == "{}") { return; }
    int _counter = 0;
 
    Dictionary<String, String> _batchStatusTypes =
        BatchTransitions.GetBatchStatusTransition(
            EnumUtils.GetValueFromName<BatchStatusType>(_dataItem["BatchStatusName"].Text));
 
    //accessing the cell content directly rather than trying to access the property of the GridEditCommandColumn
    ((ImageButton)(((GridEditableItem)e.Item)["MasterEditrecord"].Controls[0])).ImageUrl = "/controls/styles/images/editpencil.png";
 
    //accessing the cell content directly rather than trying to access the property of the GridButtonColumn           
    ImageButton _imgbtnPromote = (ImageButton)((GridDataItem)e.Item)["MasterPromoteRecord"].Controls[0];
    ImageButton _imgbtnDelete = (ImageButton)((GridDataItem)e.Item)["MasterDeleteRecord"].Controls[0];
    foreach (KeyValuePair<String, String> _kvp in _batchStatusTypes)
    {
        if (_counter == 0)
        {
            const string _jqueryCode = "if(!$find('{0}').confirm('{1}', event, '{2}'))return false;";
            const string _confirmText = "Are you sure you want to change the status of this batch {0}?";
            _imgbtnPromote.Attributes["onclick"] = string.Format(_jqueryCode, ((Control) sender).ClientID,
                                                                 string.Format(_confirmText, _kvp.Value),
                                                                 _kvp.Value);
            _imgbtnDelete.Attributes["onclick"] = string.Format(_jqueryCode, ((Control) sender).ClientID,
                                                                string.Format(_confirmText, _kvp.Key), _kvp.Key);
            _counter++;
            continue;
        }
 
        _imgbtnPromote.ImageUrl = "~/controls/styles/images/approve.png";
        _imgbtnPromote.ToolTip = string.Format("{0} batch", _kvp.Value);
        _imgbtnDelete.ImageUrl = "/controls/styles/images/decline.png";
        _imgbtnDelete.ToolTip = string.Format("{0} batch", _kvp.Key);
 
    }
}
Tags
Grid
Asked by
Tim
Top achievements
Rank 2
Answers by
Tim
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or