3

我有我的 radgrid (RAD13) 的手动更新代码。上传时它可以工作,但问题是只有网格中的第一行保存它的更新。

我认为我应该传递一个会自动递增以通过行的值

protected void UpdateButton_Click(object sender, EventArgs e)
{   
  RadGrid grid = (this.FindControl("RAD13") as RadGrid);               
  (grid.MasterTableView.GetItems(GridItemType.EditItem)[0] as GridEditableItem).FireCommandEvent(RadGrid.UpdateCommandName, string.Empty);           
}  
4

1 回答 1

2

请尝试使用以下代码片段。

ASPX

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnUpdateCommand="RadGrid1_UpdateCommand" AllowFilteringByColumn="true" AllowPaging="true"
    AllowMultiRowEdit="true">
    <MasterTableView DataKeyNames="ID" EditMode="InPlace">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="update All edit row" />

ASPX.CS

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
       new { ID = 1, Name = "Name1"},
       new { ID = 2, Name = "Name2"},
       new { ID = 3, Name = "Name3"},
       new { ID = 4, Name = "Name4"},
       new { ID = 5, Name = "Name5"}
   };

    RadGrid1.DataSource = data;
}



protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem item = e.Item as GridEditableItem;
    UpdateLogic(item);
}


protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridEditableItem item in RadGrid1.EditItems)
    {
        UpdateLogic(item);
        item.Edit = false;
    }

    RadGrid1.Rebind();
}

protected void UpdateLogic(GridEditableItem item)
{
    // perform your update logic here
}

让我知道是否有任何问题。

于 2013-07-19T10:17:40.763 回答