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

checkboxlist in gridTemplateColumn

14 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mydatafactory
Top achievements
Rank 1
Mydatafactory asked on 01 Jul 2008, 02:11 PM
Trying to modify the example 'Wizard ' of RadTabStrip I have a problem:

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jul 2008, 12:27 PM
Hi,

Try setting the AutoPostBack property for the CheckBoxList to true as shown below.

ASPX:
<asp:CheckBoxList AutoPostBack="true" ></asp:CheckBoxList> 


Shinu.
0
Mydatafactory
Top achievements
Rank 1
answered on 02 Jul 2008, 12:46 PM

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

0
Shinu
Top achievements
Rank 2
answered on 03 Jul 2008, 06:29 AM
Hi,

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.
0
Mydatafactory
Top achievements
Rank 1
answered on 03 Jul 2008, 07:45 AM
Hello 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!
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Jul 2008, 07:53 AM
Hi,

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.
0
Mydatafactory
Top achievements
Rank 1
answered on 03 Jul 2008, 08:22 AM
Thanks a lot for your quick reply!!!
0
Princy
Top achievements
Rank 2
answered on 07 Jul 2008, 10:18 AM
Hi A.,

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.
0
Mydatafactory
Top achievements
Rank 1
answered on 07 Jul 2008, 11:15 AM
Thanks a lot for the link. I tried it and it works fine!!
0
Mydatafactory
Top achievements
Rank 1
answered on 07 Jul 2008, 11:15 AM
Thanks a lot for the link. I tried it and it works fine!!
0
Kyle Parker
Top achievements
Rank 1
answered on 11 Aug 2008, 02:07 AM
I am trying to perform a similar action (drop down list instead of checkboxes), but I'm afraid I don't understand the example.

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>

0
Yavor
Telerik team
answered on 11 Aug 2008, 05:02 AM
Hello Kyle,

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.
0
Kyle Parker
Top achievements
Rank 1
answered on 11 Aug 2008, 11:48 AM
Yavor,

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
0
Princy
Top achievements
Rank 2
answered on 11 Aug 2008, 12:47 PM
Hello Kyle,

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.

0
Kyle Parker
Top achievements
Rank 1
answered on 11 Aug 2008, 03:31 PM
This worked perfectly - thank you!
Tags
Grid
Asked by
Mydatafactory
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mydatafactory
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Kyle Parker
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or