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

ObjectDataSource parameter linked to control inside CommandItemTemplate

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Davis
Top achievements
Rank 2
John Davis asked on 07 Aug 2008, 07:12 PM

Can you recommend a straightforward way or tell me how to fix the workaround?

I want an ObjectDataSource to have a parameter linked to the value of a CheckBox ("chkShowInactivesInGrid") that is inside a CommandItemTemplate.
Is there any way for the ObjectDataSource to refer to this CheckBox? (I get "not found" error.)

As a workaround I use for the parameter a CheckBox "chkShowInactive" that is on the web page, NOT inside a CommandItemTemplate.

<SelectParameters>
     <asp:ControlParameter Name="DisplayInactive" ControlID="chkShowInactive" PropertyName="Checked" />
....

<CommandItemTemplate>
      <div style="padding: 10px 0px;">
       <asp:CheckBox ID="chkShowInactivesInGrid" Text="Show Inactive" runat="server" />
      </div>
 </CommandItemTemplate>

In this workaround I hope to have the CheckBox inside CommandItemTemplate ("chkShowInactivesInGrid" ) mirror the value of the other checkbox.

I can set the value of "chkShowInactivesInGrid" using the following, BUT this event fires ONLY when the page (actually the user control) is first displayed.
When the page containing the user control is refreshed, the  chkShowInactive may have a new value but this value is not transferred to chkShowInactivesInGrid because
the following event is not fired.

        protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            PopulateOnPrerender = false;
          
            if (e.Item is GridCommandItem)
            {
                GridCommandItem cmditm = (GridCommandItem)e.Item;
                CheckBox cb = (CheckBox)cmditm.FindControl("chkShowInactivesInGrid");
                cb.Checked = chkShowInactive.Checked;
            } 
        }

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Aug 2008, 08:11 AM
Hello John,

ControlParameter will try to locate the control only in the current INamingContainer and in this case the CheckBox is inside grid item which is INamingContainer. You can use ItemCreated instead ItemDataBound to find the control in every page lifecycle.

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
John Davis
Top achievements
Rank 2
answered on 11 Aug 2008, 01:33 PM
Thanks.  ItemCreated  event occurs too soon in this case.  But I found

RadGrid1_PreRender works.  You can access the CheckBox inside the grid item using the technique shown in this post:

http://www.telerik.com/community/forums/thread/b311D-bdtkgg.aspx

John

Tags
Grid
Asked by
John Davis
Top achievements
Rank 2
Answers by
Vlad
Telerik team
John Davis
Top achievements
Rank 2
Share this question
or