Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..

VB
Protected Sub check_change(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim myConnection As SqlConnection = New SqlConnection(connectionString)
        myConnection.Open()
        '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



        Next




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,
musiw.
Posted
Updated 24-Dec-12 0:05am
v2

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



if this won't help try next :

SQL
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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900