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

GridButtonColumn empty after click

2 Answers 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattia
Top achievements
Rank 1
Mattia asked on 06 May 2014, 10:42 AM
Hi, i added a GridButtonColumn to my grid in the Page_Load event:

GridButtonColumn colEdit = new GridButtonColumn();
colEdit.UniqueName = "Edit";
colEdit.HeaderText = "Edit";
colEdit.Text = "Edit";
RadGrid1.MasterTableView.Columns.Add(colEdit);

When i click on it, i handle the RadGrid1_ItemCommand event:

 protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
if (e.CommandName == "Edit")
...
...
}


After the event the GridButtonColumn is empty, why?
Other problem is that the e.CommandName is alway empty, why?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 06 May 2014, 11:56 AM
Hi Mattia,

When creating a RadGrid on a Page_Load event, the columns or detail tables should be added to the corresponding collection first and then values for the properties of this instance should be set. Please correct your code as below.

C#:
RadGrid RadGrid1;
protected void Page_Load(object sender, EventArgs e)
{
    RadGrid1 = new RadGrid();
    RadGrid1.ID = "RadGrid1";
    PlaceHolder1.Controls.Add(RadGrid1);
    RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
    RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
 
    if (!IsPostBack)
    {     
        //Your code
 
        GridButtonColumn colEdit = new GridButtonColumn();
        RadGrid1.MasterTableView.Columns.Add(colEdit);//Add here
        colEdit.UniqueName = "Edit";
        colEdit.HeaderText = "Edit";
        colEdit.Text = "Edit";
        colEdit.CommandName = RadGrid.EditCommandName;
    }
}
void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    //Your code
}

Thanks,
Princy
0
Mattia
Top achievements
Rank 1
answered on 06 May 2014, 12:36 PM
HI, thank you for the reply. Both problems solved!
Tags
Grid
Asked by
Mattia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Mattia
Top achievements
Rank 1
Share this question
or