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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select multiple check boxes 1

Status
Not open for further replies.

yosie2007

Technical User
Jun 23, 2007
46
US
I have a gridview where the user select a check box and place their order. I am not sure how I can pass the "SP" values from the first page to the next page where fillout form page to place those orders.


<asp:GridView ID="gvPlansProposal" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
EmptyDataText="No records found" PagerSettings-Mode="NumericFirstLast" PageSize="15"
OnPageIndexChanging="gvPlansProposal_PageIndexChanging" OnSorting="gvPlansProposal_Sorting"
runat="server" CellPadding="4" ForeColor="#333333">

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="White" />
<PagerStyle BackColor="#284775" Font-Names="Verdana" Font-Size="Small" ForeColor="White" HorizontalAlign="Center" />
<RowStyle Font-Names="Verdana" Font-Size="Small" BackColor="#F7F6F3" ForeColor="#333333" />

<Columns>

<asp:BoundField DataField="let" HeaderText="Letting Date" SortExpression="let" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="sp" HeaderText="S.P. Number" SortExpression="sp" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="desp" HeaderText="Job Description" SortExpression="desp" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="loc" HeaderText="Location" SortExpression="loc" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Select Projects">

<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>

</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerSettings Mode="NumericFirstLast" />
<EmptyDataTemplate>
<asp:CheckBox ID="order" runat="server" />
</EmptyDataTemplate>

</asp:GridView>
<asp:Button ID="btnButton"
runat="server" Text="Place Your Order" /><br />
 
What exactly is your question? So you want to pass values from the selected row in the gridview to another page?
 
Yes that is my question and then when the selected value passed to the second page I have a form for the user to fill out and submit by e-mail.I just need to know how to select from multiple check boxes and pass it to next page. thanks
 
You can have a button, that when pressed will get the data. Use the RowDataBound event of the grid. As each row binds, get a reference to the checkbox. Then check if it is checked or not. If it is, you can add the values to an array or collection, or datatable.. or what ever, and pass that in a sesion variable to the next page.
 
thank you jbenson001 for the tip. can you give me a sample code to start with . I am struggling with this code
Protected Sub btnButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnButton.Click
'Error: Converting Methods, Functions and Constructors
'Error: Converting If-Else-End If Blocks

' StringBuilder object
Dim str As StringBuilder = New StringBuilder()

' Select the checkboxes from the GridView control
Dim i As Integer
For i = 0 To gvPlansProposal.Rows.Count - 1 Step i + 1
Dim row As GridViewRow = gvPlansProposal.Rows(i)
Dim isChecked As Boolean
If isChecked = (CType(row.FindControl("CheckBox1"), CheckBox)).Checked Then

End If


' If (isChecked) Then

' Column 2 is the name column
str.Append(gvPlansProposal.Rows(i).Cells(2).Text)
' End If
Next

' prints out the result
Response.Write(str.ToString())

End Sub
 
Me said:
Use the RowDataBound event of the grid
[/quote Me]
Code:
    Protected Sub gvPlansProposal_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPlansProposal.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim cb As New CheckBox
            cb = e.Row.FindControl("CheckBox1")

            If cb.Checked Then
                ''add the values you want from e.Row.Cells(index#).Text to some collection
                ''then add to a session var. which will be available to you on the next page
            End If
        End If
    End Sub
 
thank you again for the help. for some reason even if I checked the check box I am getting false for all of them and the code is not executing. thanks
 
Yes, Mark
Is that the reason why this code is not executing?

Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
PopulatePlanProposalGridView()
End If


End Sub
Is that the reason why this code is not executing. It does not even get in between this line

If cb.Checked Then
Dim Test As String = e.Row.Cells(2).Text
''add the values you want from e.Row.Cells(index#).Text to some collection
''then add to a session var. which will be available to you on the next page
End If


Protected Sub gvPlansProposal_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPlansProposal.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cb As New CheckBox
cb = e.Row.FindControl("CheckBox1")
If cb.Checked Then
Dim Test As String = e.Row.Cells(2).Text
''add the values you want from e.Row.Cells(index#).Text to some collection
''then add to a session var. which will be available to you on the next page
End If
End If
Response.Write("Test")
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top