Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gridview/checkbox list

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
using a detailsview and a radiobutton checklist- trying to loop through checkboxlist and collect the values separating with a comma (I want to add them to one field in a SQL table)

Code:
 Protected Sub HChkEvents_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim HChkEvents As String = String.Empty
        Dim c As CheckBoxList = CType(DetailsView1.FindControl("HChkEvents"), CheckBoxList)
        Dim item As ListItem
        For Each item In c.Items
            If item.Selected Then
                HChkEvents = HChkEvents + item.Text.ToString & ","
            End If
        Next
        Session.Add("achieve", HChkEvents)
    End Sub

This is in my code behind page...

in my default.aspx page I have it binding to the session variable... then inserting the value of the variable to SQL- only takes the first one selected, not looping... help!

Insert parameters:
Code:
<InsertParameters>
                                                <asp:ControlParameter ControlID="HRegID" Name="HRegID" PropertyName="Text" Type="String" />
                                                <asp:Parameter Name="HRegName" Type="String" />
                                                <asp:Parameter Name="HRegArrival" Type="String" />
                                                <asp:Parameter Name="HRegDepart" Type="String" />
                                                <asp:FormParameter FormField="HRegRoom" Name="HRegRoom" />
                                                <asp:Parameter Name="HSharingWith" Type="String" />
                                                <asp:Parameter Name="HRegBadge" Type="String" />                                                
                                                <asp:SessionParameter Name="HChkEvents" SessionField="achieve" />
                                           </InsertParameters>

call on the checkboxlist itself:
Code:
  <asp:TemplateField HeaderText="Events">
                                                    <InsertItemTemplate>
                                                        &nbsp;<asp:CheckBoxList ID="HChkEvents" runat="server" RepeatDirection="Horizontal" Width="416px" SelectedValue='<%# Bind(&quot;achieve&quot;) %>' OnSelectedIndexChanged="HChkEvents_SelectedIndexChanged">
                                                            <asp:ListItem Value="Sunday Kick Off Reception">Sunday Kick Off Reception</asp:ListItem>
                                                            <asp:ListItem Value="Monday Cont. Breakfast">Monday Cont. Breakfast</asp:ListItem>
                                                            <asp:ListItem Value="Monday Lunch">Monday Lunch</asp:ListItem>
                                                            <asp:ListItem Value="Tuesday Breakfast">Tuesday Breakfast</asp:ListItem>
                                                            <asp:ListItem Value="Thursday Luncheon">Thursday Luncheon</asp:ListItem>
                                                        </asp:CheckBoxList>
                                                    </InsertItemTemplate>
                                                </asp:TemplateField>


 
sorry, not radiobuttonlist, checkboxlist... SORRY
 
to start, I would drop the data source control altogether. after that you have full control of the UI and the data. You can then get the selected values from the checkboxlist and build your parameter value for the command.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top