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

DataList within a RadGrid Question

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 06 Dec 2010, 06:18 PM

I have a RadGrid that has a DataList inside of each row. 
The DataList has checkboxes in them. 

Example:
Let's say the grid has four rows, and the datalist inside each row has three rows itself. 

When a user checks one of the checkboxes in the datalist, I need the same checkbox in the the other three rows with the same value to get checked.  Would it be easier for me to do it client side or server side?  Also, any help to achieve this would be great.
Here a sample of the code:

<telerik:GridTemplateColumn HeaderText="Optional Languages" HeaderStyle-Width="100%" ItemStyle-HorizontalAlign="Left" Groupable="false">
   <ItemTemplate>
   <asp:DataList ID="DataListl" OnItemDataBound="DataList1_ItemDataBound" RepeatLayout="Table" Width="100%" ItemStyle-BorderStyle="None" runat="server">
    <ItemTemplate>
            <asp:CheckBox ID="CheckboxOptional1" runat="server" />                                   
            <asp:Literal ID="LiteralOptional1" Visible="false" runat="server" />
         </ItemTemplate>
      </asp:DataList>
   </ItemTemplate>
</telerik:GridTemplateColumn>

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Dec 2010, 12:27 PM
Hello Michael,

In order to achieve this try the following code snippet in CheckedChanged event of CheckBox.

C#:
protected void CheckboxOptional1_CheckedChanged(object sender, EventArgs e)
 {
  CheckBox selectedChkbox = (CheckBox)sender;
  GridDataItem item = (GridDataItem)selectedChkbox.NamingContainer.NamingContainer.NamingContainer;
  int index = ((selectedChkbox.NamingContainer as DataListItem)).ItemIndex;
  foreach (GridDataItem dataitem in RadGrid1.Items)
   {
     if (item.ItemIndex != dataitem.ItemIndex)
      {
        DataList list = (DataList)dataitem.FindControl("DataListl");
        CheckBox chk = (CheckBox) list.Items[index].FindControl("CheckboxOptional1");
        chk.Checked = selectedChkbox.Checked;
      }
    }
 }

-Shinu.
0
Mike
Top achievements
Rank 1
answered on 08 Dec 2010, 03:14 PM
Shinu,

You are AWESOME!

Thank you!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or