Reference to Control in a RadGrid CommandItemTemplate

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    70 posts
    Member since:
    Oct 2008

    Posted 05 Oct 2010 Link to this post

    Hi,

    The <WhereParameters > of an OpenAccessDataSource can include an <asp:ControlParameter ControlID="xxx" Propertyname="yyy" Name="zzz" and so on />

    This can reference a Control which is located on the page, but it does not appear to be able to refer to a control which is located within the CommandItemTemplate of a RadGrid.

    Further I would like to use a "UserControl ascx" to contain the various controls which I want to appear in the CommandItemTemplate - at the moment I can't get it to work when the Control is directly within the CommandItemTemplate or within a user control within it.


    Basically I have a RadGrid linked through an OpenAccessDataSource to display data from the database, and I want to apply more sophisticated filtering than is possible using the built-in filter facilities of the grid (e.g. selection of multiple items from a drop down combo).

    I would like these "filter controls" to be inside the command item of the grid (so that they take up one row of my limited screen real estate i.e. they are on the same line as the refresh and other grid command buttons). But when I move the control inside the Command Item it is no longer "visible" to the Control Parameter.

    And as mentioned above, in fact I really need a "multi-select" Combo, which I have successfully created within a UserControl (ascx) (so that I dont' have to keep repeating the code to handle multi-selects) and which I can refer to when the User Control is outside the Command Item, but not when it is within - but one step at a time.

  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 08 Oct 2010 Link to this post

    Hello Andrew,

    I suggest you to initialize the OpenAccessDataSource’s control parameters within the RadGrid.ItemCreated event handler and set the ControlID to the control’s UniqueID:

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            GridCommandItem commandItem = e.Item as GridCommandItem;
            LinkButton button = commandItem.FindControl("LinkButton1") as LinkButton;
            if (button != null)
            {
                ControlParameter parameter = new ControlParameter("LinkButton1", button.UniqueID, "CommandName");
                this.OpenAccessDataSource1.WhereParameters.Add(parameter);
            }
        }
    }

    Hope that helps.

    All the best,
    Damyan Bogoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top