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

Create a RadGrid programmatically with a GridTemplateColumn in the RadMultiPage_PageViewCreated event.

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 29 Oct 2008, 06:50 PM
Hopefully this is easier than I am making it.
 
I have a page with a MultipageView.  I am employing the lazy loading method described elsewhere on the forum.  So that the pageview of each tab is created programmatically in the PageViewCreated event.

Inside of each tab I have a grid.  Which is bound to an object, but also contains a checkbox column which is checkable, and not bound to anything.  In the past I have used a GridTemplateColumn to create this scenario. 

I read up on implementing the ITemplate interface, and came up with a very simple ItemTemplate to use.

public class CheckboxItemTemplate : ITemplate
{
    public string CheckBoxID;
    public CheckBox _checkbox;

    public CheckboxItemTemplate(string checkboxID)
    {
        this._checkbox = new CheckBox();
        this.CheckBoxID = checkboxID;
        this._checkbox.ID = this.CheckBoxID;
    }
    
    public void InstantiateIn(System.Web.UI.Control container)
    {
        this._checkbox.AutoPostBack = false;
        container.Controls.Add(this._checkbox);
    }
}
 
When I implement this as I described, by building a grid programmatically in the PageViewCreated event, and assigning this item template to a GridTemplateColumn I get my grid with all the columns I would expect, but my CheckBoxItemTemplate Column only has 1 row that is as large as all the rows in the other columns of my grid, inside this one giant cell is a single checkbox control.

Note, I do notice that I am supposed to assign my custom item template to a grid in the Page_Init event.  Because this is not possible in my case (since the grid doesn't exist until the RadPageView control is created to place it on).  I was hoping that the PageViewCreated event would work out the same, because it does fire before Page_Load.  but this does not appear to be the case.

Any suggestions?  I would love to use a GridCheckBoxColumn instead, but I can't seem to get it to render not read only.  Nothing else in my grid should be editable, and the checkboxes are not databound.

I'm going to explore some other methods to achieve the same effect, but nothing I have come up with to try seems very promising at this point.

Thanks for your time.

1 Answer, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 29 Oct 2008, 07:41 PM
Figured this one out.  Can't share an instance of a control across all the Instantiation containers, which does make sense now that I am looking it.  So all you have to do is change our Custom template to:

public class CheckboxItemTemplate : ITemplate
{
    public string CheckBoxID;
    public CheckBox _checkbox;

    public CheckboxItemTemplate(string checkboxID)
    {
        this.CheckBoxID = checkboxID;
    }
    
    public void InstantiateIn(System.Web.UI.Control container)
    {
        this._checkbox = new CheckBox();
        this._checkbox.ID = this.CheckBoxID;
        this._checkbox.AutoPostBack = false;
        container.Controls.Add(this._checkbox);
    }
}

and all is well.  Note that we in fact can use the PageViewCreated event instead of Page_Init because, though it fires after Page_Init, it still fires before we set up ViewState.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Share this question
or