
In the second tab one can upload one or more files.
In the third (last) tab a grid shows the uploaded files.
In the grid I have a checkboxlist loaded with values form a database.
Here comes my problem: I want to update the preview each time someone selects a checkbox. In the codebehind I cannot find the ID of the checkboxlist, so I'm not able to use the 'SelectedIndexChanged' or 'OnCheckChanged'.
Has this something to do with putting the checkboxlist in an itemtemplate?
<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="dsFiles" | |
GridLines="None" Skin="Office2007" AutoGenerateColumns="False" | |
Width="750px"> | |
<MasterTableView datasourceid="dsFiles" CellPadding="0" CellSpacing="0"> | |
<Columns> | |
<telerik:GridBoundColumn DataField="FileName" HeaderText="File" Sortexpression="FileName" ItemStyle-Width="200px"> | |
<ItemStyle Width="200px"></ItemStyle> | |
</telerik:GridBoundColumn> | |
<telerik:GridTemplateColumn> | |
<ItemTemplate> | |
<asp:CheckBoxList ID="chkTasks" runat="server" | |
DataTextField="SoortBewerking" DataValueField="BewerkingId" | |
DataSourceID="dsTasks" Width="550px" TextAlign="Right" | |
RepeatLayout="Table" OnSelectedIndexChanged="SelectedIndexChanged" | |
DataMember="DefaultView" ondatabinding="SelectedIndexChanged" | |
ontextchanged="SelectedIndexChanged"> | |
</asp:CheckBoxList> | |
</ItemTemplate> | |
</telerik:GridTemplateColumn> | |
</Columns> |
14 Answers, 1 is accepted

Try setting the AutoPostBack property for the CheckBoxList to true as shown below.
ASPX:
<asp:CheckBoxList AutoPostBack="true" ></asp:CheckBoxList> |
Shinu.

Thanks for your reply. I changed the Autopostback, but it doesn't change my problem: I cannot find the CheckboxID in the code-behind.

Try accessing the CheckBox in the code behind as shown below.
ASPX:
<telerik:GridTemplateColumn UniqueName="TempCol" HeaderText="TempCol" > |
<ItemTemplate> |
<asp:CheckBoxList ID="chkTasks" AutoPostBack="true" runat="server" OnSelectedIndexChanged="chkTasks_SelectedIndexChanged" OnTextChanged="chkTasks_TextChanged" ></asp:CheckBoxList> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
GridDataItem item = (GridDataItem)e.Item; |
CheckBoxList chkbxlst = (CheckBoxList)item["TempCol"].FindControl("chkTasks"); |
} |
} |
protected void chkTasks_SelectedIndexChanged(object sender, EventArgs e) |
{ |
} |
protected void chkTasks_TextChanged(object sender, EventArgs e) |
{ |
} |
Thanks
Shinu.

thanks for your reply. Unfortunately I'm not that familiar with CS that I can translate the code. I'll try, but if you have a VB.net code it will help a lot!

Here is the code in VB:
Protected Sub RadGrid2_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim chkbxlst As CheckBoxList = DirectCast(item("TempCol").FindControl("chkTasks"), CheckBoxList) |
End If |
End Sub |
Protected Sub chkTasks_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) |
End Sub |
Protected Sub chkTasks_TextChanged(ByVal sender As Object, ByVal e As EventArgs) |
End Sub |
Thanks
Princy.


Here is a link which helps to convert code from C# toVB. Have a look at it.
http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
Thanks
Princy.



Based on the code snippet provided, how does finding the the checkbox control in the ItemDataBound get the ID to the SelectedIndexChanged event? The SelectedIndexChanged event is what needs to perform the action, correct? Or can the ItemDataBound do it?
In my example, I need a selection in the drop down list (i.e., "Other") to make secondary TextBox to appear where the user can enter text describing the "other" selection (code snippet) below.
Thanks,
Kyle
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlRecruitmentSource" CssClass="GridEditDropDown" AutoPostBack="true" OnSelectedIndexChanged="ddlRecruitmentSource_SelectedIndexChanged" />
<asp:RequiredFieldValidator runat="server" ID="rfvRecruitmentSource" ControlToValidate="ddlRecruitmentSource" ErrorMessage="*" Display="Dynamic" InitialValue="0"></asp:RequiredFieldValidator>
<asp:Panel runat="server" ID="pnlRecruitmentSourceOther" Visible="false">
<br />
<asp:TextBox runat="server" ID="tbxRecruitmentSourceOther" CssClass="GridTextBox"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rfvRecruitmentSourceOther" ControlToValidate="tbxRecruitmentSourceOther" ErrorMessage="*" Display="Dynamic"></asp:RequiredFieldValidator>
</asp:Panel>
</EditItemTemplate>
You can use the ItemDataBound event handler, to get a reference to the DropDown control. You can then assign a SelectedIndexChanged event handler to it. Either on the client, or on the server, you can toggle on the visibility of the TextBox control.
Let me know if this is a suitable option for you.
Kind regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thank you for the quick response. Yes, this is a suitable option, but I'm a little slow on the actual implementation and usage - what I've tried so far isn't working. Would you be able to provide a code snippet based on this recommendation?
Thank you,
Kyle Parker

Try out the following code to implement the required scenario.
cs:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) |
{ |
DropDownList ddl = (DropDownList)sender; |
GridEditableItem edititem = (GridEditableItem)ddl.NamingContainer; |
TextBox txtbx = (TextBox)edititem["TemplateColumn"].FindControl("TextBox1"); |
if (ddl.SelectedItem.Text =="Paris") |
{ |
txtbx.Visible = true; |
} |
} |
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
<EditItemTemplate> |
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" DataSourceID="SqlDataSource1" DataTextField="City" DataValueField="City" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> |
</asp:DropDownList> |
<asp:TextBox ID="TextBox1" Visible="false" runat="server"></asp:TextBox> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
Thanks
Princy.
