[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Datagrid

Posted on 2005-04-06
7
Medium Priority
?
304 Views
Last Modified: 2010-04-23
In VB.NET 2003, how can I:

1. Get how many rows are selected in a DataGrid (something like DataGrid1.SelectedRowsCount)
2. Loop through the table, row by row, and find out for each row if it is selected or not.
3. Loop through the table, row by row, and get the actual value for specific columns of each row

Basically, I need to check of there is at least one row selected in the DataGrid. If so, I have to loop through the DataGrid rows collection, and for each selected row, get the values for some of the columns.

Thanks
0
Comment
Question by:SETP
  • 5
7 Comments
 
LVL 8

Expert Comment

by:mani_sai
ID: 13717355
1)To count the rows from the datasource bound to the grid. ie:

   CType(Datagrid.DataSource, DataTable).Rows.Count

0
 
LVL 8

Expert Comment

by:mani_sai
ID: 13717379
2) if you have a checkbox in your datagrid you could do something like this:

For i = 0 To datagrid2.Items.Count - 1
            If CType(datagrid2.Items(i).FindControl("checkbox3"), CheckBox).Checked() Then
                flag = True
            Else
                flag = False
            End If
        Next

0
 

Author Comment

by:SETP
ID: 13717398
Mmm... so doesn't look like theres an easy way to work with the DataGrid itself. I guess working with the DataSource associated with the DataGrid's DataSource property might be a better solution. Do you agree?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:mani_sai
ID: 13717417
3) to get the value if your checkbox is checked:

Dim str as String
        For i = 0 To datagrid2.Items.Count - 1
            If CType(datagrid2.Items(i).FindControl("checkbox3"), CheckBox).Checked() Then
                str= datagrid2.Items(i).Cells(2).Text    'Get the value here
            End If
        Next
0
 
LVL 8

Expert Comment

by:mani_sai
ID: 13717425
I guess working with the DataSource associated with the DataGrid's DataSource property might be a better solution. Do you agree?

Yes.
0
 
LVL 8

Accepted Solution

by:
mani_sai earned 1500 total points
ID: 13717501
3) to store the multiple values in the string variable comma separated:
this is just an example, you can you use your own logic here...

Dim str as String
        For i = 0 To datagrid2.Items.Count - 1
            If CType(datagrid2.Items(i).FindControl("checkbox3"), CheckBox).Checked() Then
                If str  = "" Then
                str= datagrid2.Items(i).Cells(2).Text    'Get the value here
                Else
                str= str + "," + datagrid2.Items(i).Cells(2).Text    'Get the value here
                End If
            End If
        Next
0
 

Expert Comment

by:jxs0900
ID: 14889501
How can you do this for a windows app not a web app?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question