Click here to Skip to main content
12,750,464 members (37,512 online)
Rate this:
Please Sign up or sign in to vote.
hi all,

situation: in a popup window, user will select multiple rows from gridview of items they want to delivery.and then when they click OK the data will be passed to gridview in parent window showing the data that they had selected just now.

question: how to get the value of multiple selected rows to be bind in the gridview.if only 1 row they selected i think i manage to do that, but when they select multiple rows how to get the value..

Protected Sub check_change(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim myConnection As SqlConnection = New SqlConnection(connectionString)
        'Dim ID As Integer = Convert.ToInt32(gridroda.DataKeys(row.RowIndex).Value)
        'Label1.Text = ID

        For k As Integer = 0 To gridroda.Rows.Count
            Dim row As GridViewRow = DirectCast(DirectCast(sender, CheckBox).NamingContainer, GridViewRow)
            rowIndex = row.DataItemIndex
            Dim l1 As String = DirectCast(gridroda.Rows(rowIndex).Cells(1).FindControl("tindakan"), Label).Text.ToString()
            Label2.Text = l1
            Dim l2 As String = DirectCast(gridroda.Rows(rowIndex).Cells(2).FindControl("wheelno"), Label).Text.ToString()
            Label3.Text = l2
            Dim l3 As String = DirectCast(gridroda.Rows(rowIndex).Cells(3).FindControl("axletype"), Label).Text.ToString()
            Label4.Text = l3
            Dim l4 As String = DirectCast(gridroda.Rows(rowIndex).Cells(4).FindControl("smhref"), Label).Text.ToString()
            Label5.Text = l4


this is the code for getting the value of multiple selected rows..
when i get the values in those labels(label2-label5) i want to bind it to data table of gridview.

please help me.i really need help

thanks in advance,
Posted 24-Dec-12 1:01am
Updated 24-Dec-12 1:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi, first of all do the next:
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
DataGridView1.MultiSelect = true;

if this won't help try next :

You could override SetSelectedRowCore or SetSelectedCelCore and perform your custom selection.

MSDN Quote:

The DataGridView control uses this method whenever it changes the selection state of a cell. The selection state changes without regard to the current SelectionMode property value, and without changing the CurrentCell property value. This is useful when you want to implement your own selection modes

Of course this means you will have to use an derived datagrid and not the standard one.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I would suggest to use client side technique for this. Add a hidden field in the parent window. On clicking OK button of the child window, fire a javascript event that check all the selected checkboxes of the gridview and store their id's seperated by a '$' or '@' in a hidden field. Then pass this single string to the parent window using:

window.opener.form.parentshiddenfieldid.value = 'you hidden field value';

Close the popup window and fire a postback event on parent window using javascript in which you seperate the string by '$' or '@' whatever you use. This will give you the row id's of selected records in popup window. Based on these id's fetch the record's from database and bind the gridview.
musiw 26-Dec-12 6:39am
can you give me some code examples?i dont know javascript and all the passing function.thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100