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

Checkbox problem inside RadWindow

1 Answer 106 Views
Window
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 07 Jun 2010, 03:40 PM
Hi!
I have a RadGrid with a checkbox inside a template column. When I place the grid inside a RadWindow and the checkbox is marked as checked in codebehind it don't become checked when displayed. It works fine when it's not placed inside a RadWindow. Anyone has any suggestions?
Example code below.

/Håkan

<asp:Button ID="Button1" runat="server" Text="Open" OnClick="Button1_Click" />      
          
<telerik:RadWindow ID="RadWindow1" runat="server">  
    <ContentTemplate> 
        <telerik:RadGrid id="RadGrid1" runat="server">  
            <MasterTableView AutoGenerateColumns="false">  
                <Columns> 
                    <telerik:GridTemplateColumn>                              
                        <ItemTemplate>                                  
                            <asp:CheckBox id="chkSelect" runat="server" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridBoundColumn DataField="Name" /> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid>         
    </ContentTemplate> 
</telerik:RadWindow> 
protected void Button1_Click(object sender, EventArgs e)  
{  
    List<object> list = new List<object>();  
    list.Add(new { ID = 1, Name = "Item A" });  
    list.Add(new { ID = 2, Name = "Item B" });  
    list.Add(new { ID = 3, Name = "Item C" });  
 
    RadGrid1.DataSource = list;  
 
    RadGrid1.DataBind();  
 
    ((CheckBox)RadGrid1.Items[1].FindControl("chkSelect")).Checked = true//Select Item B  
    RadWindow1.VisibleOnPageLoad = true;  

1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 10 Jun 2010, 02:32 PM
Hi Håkan,

I already answered your support thread and for your convenience and for others who might encounter the same problem I pasted it below:

Hello Andreas,

Thank you for the provided demo, I examined it and I was able to reproduce the problem. It comes from the fact that the RadWindow when used with ContentTemplate databinds its children. This being said, in order to solve the problems please do the following:

1) Remove the explicit call to DataBind() for the combo and the grid - simply leave the datasource as shown below:

RadGrid1.DataSource = list;
RadComboBox1.DataSource = list;
RadComboBox1.DataTextField = "Name";
RadComboBox1.DataValueField = "ID";
RadComboBox1.AppendDataBoundItems = true;
// Insert choose item
RadComboBox1.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("Choose", "-1"));
RadWindow1.VisibleOnPageLoad = true;
 
2) Move the code which selects the checkbox to the DataBound event of the grid as shown below:

protected void RadGrid1_DataBound(object sender, EventArgs e)
{
    if (RadGrid1.Items.Count > 0)
    {
        //// Select Item B checkbox
        ((CheckBox)RadGrid1.Items[1].FindControl("chkSelect")).Checked = true;
    }
}

I hope that my reply is helpful, let me know how it goes.

Sincerely yours,
Svetlina
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.
Tags
Window
Asked by
Håkan
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or