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

Delete Button not fire event

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leuk
Top achievements
Rank 1
Leuk asked on 18 Nov 2010, 05:54 PM
I am using a grid control witch is created dynamically from server but am facing a problem.The delete button never fires the event DeleteCommand.Below is my c# code

private void GridPowerControl()
{
    RadGrid1.Columns.Clear();
 
    RadGrid1.PageSize = 5;
    RadGrid1.AllowPaging = true;
    RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
    RadGrid1.AutoGenerateColumns = false;
    RadGrid1.ShowStatusBar = true;
     
    RadGrid1.MasterTableView.EditFormSettings.UserControlName = ControlS.POWER_CONTROL;
    RadGrid1.MasterTableView.EditFormSettings.EditFormType = Telerik.Web.UI.GridEditFormType.WebUserControl;
 
    RadGrid1.MasterTableView.PageSize = GlobalParams._PageRowNum;
    RadGrid1.MasterTableView.Width = Unit.Percentage(100);
    RadGrid1.MasterTableView.CommandItemDisplay = Telerik.Web.UI.GridCommandItemDisplay.Top;
    RadGrid1.MasterTableView.DataKeyNames = new string[] { "ID" };
 
    GridEditCommandColumn editColumn;
    editColumn = new GridEditCommandColumn();
    editColumn.UniqueName = "EditCommandColumn";
    RadGrid1.MasterTableView.Columns.Add(editColumn);
 
    GridButtonColumn deleteButton;
    deleteButton = new GridButtonColumn();
    deleteButton.UniqueName = "Delete";
    deleteButton.Text = Resources.Global.DELETE;
    deleteButton.CommandName = "Delete";
    RadGrid1.MasterTableView.Columns.Add(deleteButton);
 
    GridBoundColumn boundColumn;
    boundColumn = new GridBoundColumn();
    boundColumn.DataField = "Name";
    boundColumn.UniqueName = "Name";
    boundColumn.HeaderText = Resources.Global.NAME;
    RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
    boundColumn = new GridBoundColumn();
    boundColumn.DataField = "Tag";
    boundColumn.UniqueName = "Tag";
    boundColumn.HeaderText = Resources.Global.TAG;
    RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
    boundColumn = new GridBoundColumn();
    boundColumn.DataField = "Info";
    boundColumn.UniqueName = "Info";
    boundColumn.HeaderText = Resources.Global.INFO;
    RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
    boundColumn = new GridBoundColumn();
    boundColumn.DataField = "Geotag";
    boundColumn.UniqueName = "Geotag";
    boundColumn.HeaderText = Resources.Global.GEO_TAG;
    RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
}
protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{
    string Test = string.Empty;
}
 
and this is the asp code
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None"
    AllowPaging="True" CssClass="RadGrid"
    AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="True"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
    OnInsertCommand="RadGrid1_InsertCommand"
    OnDeleteCommand="RadGrid1_DeleteCommand">
    <MasterTableView>
    <RowIndicatorColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>
 
    <ExpandCollapseColumn>
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
    </MasterTableView>
 
    <ClientSettings>
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
</telerik:RadGrid>
Can someone help me with my problem.Thank you

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Nov 2010, 11:00 AM
Hello Leuk,


The DeleteCommand got fired when I add the GridButtonColumn to grid in Page_Init() event. I am not sure about your case and I am guessing that you are trying in some other event.
Programmatic creation

Could you provide some more information about your code if this does not help?


-Shinu.
0
Leuk
Top achievements
Rank 1
answered on 19 Nov 2010, 11:49 AM
GridButtonColumn deleteButton;
deleteButton = new GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(deleteButton);
deleteButton.UniqueName = "Delete";
deleteButton.Text = Resources.Global.DELETE;
deleteButton.CommandName = "Delete";
The solution was very simple but took me a day to find.I have first to add the GridButtonColumn to the grid and then asign properties on it.
Tags
Grid
Asked by
Leuk
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Leuk
Top achievements
Rank 1
Share this question
or