C# RadGrid ItemDataBound未显示对网格中第一项的更改

C# RadGrid ItemDataBound未显示对网格中第一项的更改,c#,radgrid,telerik-grid,C#,Radgrid,Telerik Grid,我知道我一定错过了什么。如果我在RadGrid的ItemDataBound事件中对datagriditem进行更改,则在第一次加载页面时,更改不可见,直到我通过CommandItem for refresh刷新网格,我才看到对DataItem的更改。我已验证是否触发了ItemDataBound事件,并且我要替换的值实际上是否具有正确的值 背景: 我有一个创建RadGrid的类。然后通过.aspx的代码将其实例化并加载到.aspx页面。这是一个主/详细数据网格,如果这有什么区别的话 protect

我知道我一定错过了什么。如果我在RadGrid的ItemDataBound事件中对datagriditem进行更改,则在第一次加载页面时,更改不可见,直到我通过CommandItem for refresh刷新网格,我才看到对DataItem的更改。我已验证是否触发了ItemDataBound事件,并且我要替换的值实际上是否具有正确的值

背景: 我有一个创建RadGrid的类。然后通过.aspx的代码将其实例化并加载到.aspx页面。这是一个主/详细数据网格,如果这有什么区别的话

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);
    }
}
protected void Page_Init(对象源,事件参数e)
{
这是.uuu activeBatchesRadGrid=activeBatchesRadGrid.GridDefinition(“activeBatchesRadGrid”);
this.placeholder 1.Controls.Add(this.\u activeBatchesRadGrid);
此.uu activeBatchesRadGrid.ItemDataBound+=新的GridItemEventHandler(activeBatchesRadGrid_ItemDataBound);
}
私有void ActiveBatchesRadGrid_ItemDataBound(对象发送方,GridItemEventArgs e)
{
GridDataItem _dataItem=e.项作为GridDataItem;
if(_dataItem==null)返回;
BatchStatusType _batchStatus=EnumUtils.GetValueFromName(_dataItem[“BatchStatusName”].Text);
字典\u batchStatusTypes=
BatchTransitions.GetBatchStatusTransition(\u batchStatus);
GridButtonColumn\u btnPromote=
((GridButtonColumn)this.u activeBatchesRadGrid.MasterTableView.GetColumn(“MasterPromoteRecord”);
网格按钮柱删除=
((GridButtonColumn)this.u activeBatchesRadGrid.MasterTableView.GetColumn(“MasterDeleteRecord”);
foreach(batchStatusTypes中的KeyValuePair项目)
{
_btnPromote.Text=_item.Value.ToString();
_btnPromote.ConfirmText=string.Format(“确实要将此批处理提升到{0}状态吗?”,
_项目(价值);
_btnDelete.Text=string.Format(“将批处理降级为{0}状态。”,_item.Key.ToString());
_btnDelete.ConfirmText=string.Format(“确实要将此批处理降级为{0}状态吗?”,
_项目(关键);
}
}

我想我会发布解决这个问题的解决方案。然而,我仍然相信我最初发布的正确实现应该会起作用。如果它适用于除第一个datagrid行以外的所有项目,那么我认为该控件存在一个缺点

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);

    }
}
private void ActiveBatchesRadGrid\u ItemDataBound(对象发送方,GridItemEventArgs e)
{
GridDataItem _dataItem=e.项作为GridDataItem;
if(_dataItem==null)返回;
如果(_dataItem.KeyValues==“{}”){return;}
int _计数器=0;
字典类型=
BatchTransitions.GetBatchStatusTransition(
EnumUtils.GetValueFromName(_dataItem[“BatchStatusName”].Text));
//直接访问单元格内容,而不是尝试访问GridEditCommandColumn的属性
((ImageButton)((GridEditableItem)e.Item)[“MasterEditrecord”].Controls[0])。ImageUrl=“/Controls/styles/images/editpencil.png”;
//直接访问单元格内容,而不是尝试访问GridButtonColumn的属性
ImageButton _imgbtnPromote=(ImageButton)((GridDataItem)e.Item)[“MasterPromoteRecord”]控件[0];
ImageButton_imgbtnDelete=(ImageButton)((GridDataItem)e.Item)[“MasterDeleteRecord”]控件[0];
foreach(batchStatusTypes中的KeyValuePair\u kvp)
{
如果(_计数器==0)
{
const string _jqueryCode=“if(!$find('{0}')。confirm('{1}',event'{2}'))返回false;”;
const string _confirmText=“确实要更改此批处理{0}的状态吗?”;
_imgbtnPromote.Attributes[“onclick”]=string.Format(_jqueryCode,((控件)sender).ClientID,
string.Format(_confirmText,_kvp.Value),
_kvp值);
_imgbtnDelete.Attributes[“onclick”]=string.Format(_jqueryCode,((控制)发送方).ClientID,
格式(_confirmText,_kvp.Key),_kvp.Key);
_计数器++;
继续;
}
_imgbtnPromote.ImageUrl=“~/controls/styles/images/approve.png”;
_imgbtnPromote.ToolTip=string.Format(“{0}batch”,_kvp.Value);
_imgbtnDelete.ImageUrl=“/controls/styles/images/declient.png”;
_imgbtnDelete.ToolTip=string.Format(“{0}batch”,_kvp.Key);
}
}

我想我会发布解决这个问题的解决方案。然而,我仍然相信我最初发布的正确实现应该会起作用。如果它适用于除第一个datagrid行以外的所有项目,那么我认为该控件存在一个缺点

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);

    }
}
private void ActiveBatchesRadGrid\u ItemDataBound(对象发送方,GridItemEventArgs e)
{
GridDataItem _dataItem=e.项作为GridDataItem;
if(_dataItem==null)返回;
如果(_dataItem.KeyValues==“{}”){return;}
int _计数器=0;
字典类型=
BatchTransitions.GetBatchStatusTransition(
EnumUtils.GetValueFromName(_dataItem[“BatchStatusName”].Text));
//直接访问单元格内容,而不是尝试访问GridEditCommandColumn的属性
((ImageButton)((GridEditableItem)e.Item)[“MasterEditrecord”].Controls[0])。ImageUrl=“/Controls/styles/images/editpencil.png”;
//直接访问单元格内容,而不是尝试访问GridButtonColumn的属性
ImageButton _imgbtnPromote=(ImageButton)((GridDataItem)e.Item)[“MasterPromoteRecord”]控件[0];
ImageButton_imgbtnDelete=(ImageButton)((GridDataItem)e.Item)[“MasterDeleteRecord”]控件[0];
foreach(KeyValuePa