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

Edit button outside grid

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 15 Mar 2012, 03:36 PM
Hello everybody, i have one grid, and here's what i want.
I have one Edit button outside the grid, and when i click on this button, i wanna check if any item has updated, if any does, i will update that on my data table, if's not, doesnt change anything.
I tryed everything is possible and nothings helps me, the last tentative, i try to obtain my data in one foreach, e copy to one dataTable, and compare with the old dataTable, if has any changes, update, ifs not, do nothing. but withoutany success.

Someone knows how can i do that 'impossible' task?
<telerik:RadGrid ID="RadGrid2" runat="server" AllowMultiRowSelection="true" Width="300px"
    OnNeedDataSource="RadGrid2_NeedDataSource" OnInsertCommand="RadGrid2_InsertCommand"
    OnItemCreated="RadGrid2_ItemCreated">
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="codigo" CommandItemDisplay="Top"
        EditMode="InPlace">
        <Columns>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="CheckBox1" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn HeaderText="Código" DataField="codigo" UniqueName="codigo"
                ReadOnly="true" Display="true" ColumnEditorID="GridTextBoxColumnEditor1" />
            <telerik:GridBoundColumn HeaderText="Descrição" DataField="descricao" UniqueName="descricao"
                ColumnEditorID="GridTextBoxColumnEditor1" />
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" />
protected void btnEditar_Click(object sender, EventArgs e)
{
     // what should i do here? ...
}
protected void RadGrid2_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        e.Item.FindControl("RefreshButton").Visible = false;
        e.Item.FindControl("RebindGridButton").Visible = false;
    }
}
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    // Atribui dados a grid.
    RadGrid2.DataSource = this.GridSource;
    this.GridSource.PrimaryKey = new DataColumn[] { this.GridSource.Columns["codigo"] };
}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Mar 2012, 11:18 AM
Hello Bruno,

You can use the FireCommandEvent to forcefully fire the Edit CommandName.
C#:
protected void edit_Click(object sender, EventArgs e)
{
  RadGrid grid = (this.FindControl("RadGrid1") as RadGrid);
  (grid.MasterTableView.GetItems(GridItemType.EditItem)[0] as GridEditableItem).FireCommandEvent(RadGrid.EditCommandName, string.Empty);
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == "Edit")
 {
 }
}

Thanks,
Princy.
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or