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

RadGrid with a repeater a nested checkboxlist

2 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 16 Mar 2011, 05:51 PM
I have a grid with a repeater with a checkboxlist inside.  I have no problem displaying the page, but when i try and get the value of the checkboxlist on the insert command in the code behind ... I cannot seem to get the values

here is an example of my code the only part that doesnt work is when i try an get the selected check boxes

Any ideas?

<asp:Repeater ID="rptMarkets" runat="server" DataSourceID="objMarkets">
    <ItemTemplate>
        <b>
            <%#DataBinder.Eval(Container.DataItem, "Market")%></b>
        <!-- Nested Repeater Level 2 - START -->
        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("MarketID") %>' />
        <asp:ObjectDataSource ID="objProducts" runat="server" SelectMethod="GetProductsByMarketsID"
            TypeName="Ceradyne.clsLibrary">
            <SelectParameters>
                <asp:ControlParameter Name="MarketID" Type="Int32" ControlID="HiddenField1" PropertyName="Value" />
            </SelectParameters>
        </asp:ObjectDataSource>
         
        <ul>
            <asp:CheckBoxList ID="clProductName" runat="server" DataSourceID="objProducts" DataTextField="ProductName" DataValueField="ProductID" RepeatColumns="3" Font-Size="8px">
            </asp:CheckBoxList>
        </ul>
        <!-- Nested Repeater Level 2 - END -->
    </ItemTemplate>
    <SeparatorTemplate>
        <hr />
    </SeparatorTemplate>
</asp:Repeater>
Protected Sub RadGrid1_InsertCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
    'save the file to the website
    Dim txtPDFFile As String = ""
    Dim Upload As RadUpload = TryCast(e.Item.FindControl("upBrochurePDF"), RadUpload)
    Dim BrochureFolder As String = Server.MapPath("~/uploads/brochures/")
    If Upload.UploadedFiles.Count > 0 Then
        For Each file As UploadedFile In Upload.UploadedFiles
            txtPDFFile = file.GetName()
            file.SaveAs(BrochureFolder & txtPDFFile, True)
        Next
    End If
 
    'check to see if this file name exists already
    '(not written yet)
 
 
    ' save the file name to the database
    objBrochure.AddBrochure(txtPDFFile)
 
    'look up the brochure id based on the filename
    objBrochure.GetBrochuresByFilename(txtPDFFile)
    Dim BrochureID As Integer = objBrochure.BrochureID
 
    'save the value of the check boxes
    Dim ProductID As Integer
    Dim i As Integer
    Dim List As CheckBoxList = DirectCast(e.Item.FindControl("clProductName"), CheckBoxList)
    For i = 0 To List.Items.Count - 1
        If List.Items(i).Selected = "true" Then
            ProductID = List.Items(i).Value
            'add brochure links to products
            objBrochure.AddBrochureProductLink(BrochureID, ProductID)
        End If
    Next
 
    Response.Redirect("/admin/Library/ManageBrochures.aspx")
End Sub

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Mar 2011, 09:50 AM
Hello Michael,

Try the following code snippet to get the CheckBoxList inside Repeater.

VB.NET:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
  {
      Repeater repeater = (Repeater)e.Item.FindControl("rptMarkets");
      CheckBoxList List = (CheckBoxList)repeater.Items[0].FindControl("clProductName");
  }

Thanks,
Princy.
0
Michael
Top achievements
Rank 1
answered on 18 Mar 2011, 01:02 AM
Princy... you are a star.. that worked perfectly
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or