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

add linkbutton to ajaxified radgrid header

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Morgan
Top achievements
Rank 2
Morgan asked on 09 Oct 2012, 11:08 PM
I have followed the code snippets from other posts on this issue to add a linkbutton to the group headers of my radgrid but on clicking the linkbutton's I get an object not specified error.

I'm adding the following code, where item is the gridgroupheaderitem and then handling the command in the radgrid_itemcommand event.
the code is added in both the radgrid_itemcreated and radgrid_itemdatabound events.
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridGroupHeaderItem)
        {
            createbutton((GridGroupHeaderItem)e.Item);
 
        }
    }
    protected void createbutton(GridGroupHeaderItem header)
    {
        if (header.DataCell.FindControl("thisGroup") == null)
        {
            Label mylab = new Label();
            mylab.ID = "thisNumber";
            DataRowView drv = header.DataItem as DataRowView;
            mylab.Text = drv["Location"].ToString();
            Label mylabno = new Label();
            mylab.ID = "thisGroup";
 
            mylabno.Text = drv["GroupOrder"].ToString();
            mylabno.Visible = false;
            GridGroupHeaderItem item = header as GridGroupHeaderItem;
            LinkButton lnk = new LinkButton();
            lnk.Text = "Move up ";
            lnk.Style.Add("margin", "3px");
            LinkButton xnk = new LinkButton();
            xnk.Text = "Move down";
            xnk.Style.Add("margin", "2px");
            xnk.Style.Add("padding", "2px");
 
            item.DataCell.Controls.Add(mylab);
            item.DataCell.Controls.Add(mylabno);
            lnk.CommandName = "Up";
            item.DataCell.Controls.Add(lnk);
            xnk.CommandName = "Down";
            item.DataCell.Controls.Add(xnk);
        }
    }


I'm guessing its related to the fact this radgrid is ajaxified, but not entirely sure.  any ideas??

2 Answers, 1 is accepted

Sort by
0
Morgan
Top achievements
Rank 2
answered on 10 Oct 2012, 12:05 AM
Update: I've tried adding these buttons via the group header template in the radgrid, and same error occurs.
Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
0
Morgan
Top achievements
Rank 2
answered on 10 Oct 2012, 12:42 AM
Sorted:  the answer was to put the buttons in the group header template and wire them up using click events not the commandname argument. 

thanks for looking.
Tags
Grid
Asked by
Morgan
Top achievements
Rank 2
Answers by
Morgan
Top achievements
Rank 2
Share this question
or