1

我需要在行编辑中使用 Telerik RadGrid 创建类似 Excel 的控件 - 列和行的动态大小。我的问题是,当我尝试在已编辑的行上调用更新命令作为回报时,它只有旧值。

我的 RadGrid 控件:

<telerik:RadGrid runat="server" ID="rgDataSheet" AutoGenerateColumns="true" AllowSorting="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"
    AllowMultiRowEdit="true" AllowPaging="false" EnableViewState="false" OnNeedDataSource="HandlerGridOnNeedDataSource"
    OnItemUpdated="GridItemUpdated" OnInsertCommand="GridInsertCommand" OnUpdateCommand="GridUpdateCommand"
    OnCancelCommand="GridCancelCommand">
    <MasterTableView runat="server" EditMode="InPlace" NoMasterRecordsText="brak rekordów"
        ShowHeadersWhenNoRecords="true" AllowCustomSorting="false" EnableColumnsViewState="false"
        AllowSorting="false" AllowFilteringByColumn="false" TableLayout="Fixed">
        <Columns>
            <telerik:GridEditCommandColumn UpdateText="Update" EditText="Edit" CancelText="Cancel" />
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowClick="RowClick" />
    </ClientSettings>
</telerik:RadGrid>

我的活动:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<string> datakeynames = new List<string>();

            dataSet = new DataSet();
            dataSet.Tables.Add(new DataTable());
            dataSet.Tables[0].Columns.Add("col0"); 
            dataSet.Tables[0].Columns.Add("col1"); 
            dataSet.Tables[0].Columns.Add("col2"); 
            dataSet.Tables[0].Columns.Add("col3"); 
            dataSet.Tables[0].Columns.Add("col4"); 
            dataSet.Tables[0].Columns.Add("col5"); 

            dataSet.Tables[0].Rows.Add(new object[] { "1", "11", "a", "q", "z", "n" });
            dataSet.Tables[0].Rows.Add(new object[] { "2", "12", "s", "w", "x", "m" });
            dataSet.Tables[0].Rows.Add(new object[] { "3", "13", "d", "e", "c", "," });
            dataSet.Tables[0].Rows.Add(new object[] { "4", "14", "f", "r", "v", "h" });
            dataSet.Tables[0].Rows.Add(new object[] { "5", "15", "g", "t", "b", "y" });
            ViewState["dataSet"] = dataSet;
            rgDataSheet.MasterTableView.DataKeyNames = new string[] { "col0", "col1", "col2", "col3", "col4", "col5" };
        }
        else
        {
            rgDataSheet.Rebind();
        }
    }

protected void HandlerGridOnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dataSet = (DataSet)ViewState["dataSet"];
        ((RadGrid)sender).DataSource = dataSet;
    }

protected void GridUpdateCommand(object source, GridCommandEventArgs e)
    {
        //here I try access changed values, in example -
        //GridEditableItem editedItem = e.Item as GridEditableItem;
        //editedItem.OwnerTableView.DataKeyValues -> it contains always old values
    }
4

1 回答 1

0

请从您的 page_load 事件中删除以下代码。不需要 Radgrid 自动管理这个东西。了解更多信息。请检查以下链接。http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html

else
    {
        rgDataSheet.Rebind();
    }
于 2012-06-07T05:50:01.110 回答