Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
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)
        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 24-Dec-12 1:01am
musiw681
Edited 24-Dec-12 1:05am
v2
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
musiw at 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
0 DamithSL 320
1 OriginalGriff 195
2 Afzaal Ahmad Zeeshan 154
3 Zoltán Zörgő 149
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
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