RadGrid ItemDataBound Не показывает изменения первого элемента в сетке - PullRequest
1 голос
/ 19 октября 2011

Я знаю, что я что-то упускаю.Если я внесу изменения в элемент данных в событии ItemDataBound RadGrid, изменения не будут видны при первой загрузке страницы, я не увижу изменения в DataItem, пока не обновлю сетку через CommandItem для обновления.Я проверил, что событие ItemDataBound запущено, и значения, которые я заменяю, действительно имеют правильные значения.

background: у меня есть класс, который создает RadGrid.Затем он создается и загружается на страницу .aspx с помощью кода для .aspx.Это таблица данных master / detail, если это имеет какое-либо значение.

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

1 Ответ

1 голос
/ 28 октября 2011

Я думал, что опубликую решение, которое я соберу, которое решит эту проблему. Однако я все еще верю, что правильная реализация, которую я первоначально разместил, должна работать. Если он работает для всех элементов, кроме первой строки таблицы данных, то я считаю, что в элементе управления есть недостаток.

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

    }
}
...