Solved

How to filter asp.net gridview rows/columns

Posted on 2011-03-04
6
1,145 Views
Last Modified: 2012-05-11
Hello experts.

I have learn how to call rows/cells from detailsview, and manage it like below code.

If JanDetailsView1.Rows(2).Cells(1).Text.ToString = " " Then
            JanDetailsView1.Rows(2).Visible = False

Open in new window


But, now I`m trying to display Gridview rows which contain specific column value. I would like to do it the same way as abow
.
My goal is to show only Gridview rows which column contain value like = John.
Example:
          Column Name:    Column SecondName:  
row1:        John                       White
row2:        John                       Black
...

Can someone give me a tip, to show me how to do it? I was writing in visual studio many ways, but could not get results.

Thank you in advance for help.


 

0
Comment
Question by:dejandejanovic
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35040678
you can just iterate through the collection checking for your value, e.g

                For Each x As DataGridViewRow In Me.JanDetailsView1.Rows
                    If Not x.Cells(0).Value = "John" Then
                        x.Visible = False
                    End If
                Next

Open in new window

0
 
LVL 13

Assisted Solution

by:agarwalrahul
agarwalrahul earned 100 total points
ID: 35041512
0
 

Author Comment

by:dejandejanovic
ID: 35041785
Thank you all for reply.

Hm, Nepaluz,
I have error on "DatagridviewRow".

Any idea?

  For Each x As [i][u][b]DataGridViewRow [/b][/u][/i]In Me.GridView1.Rows
            If Not x.Cells(0).Value = "John" Then
                x.Visible = False
            End If
        Next

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Accepted Solution

by:
nepaluz earned 400 total points
ID: 35043013
change DataGridViewRow to GridViewRow in the code suggestion. Simples ........
0
 

Author Closing Comment

by:dejandejanovic
ID: 35043122
Thanks, it works.
0
 

Author Comment

by:dejandejanovic
ID: 35099309
I just want to share my latest code:

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        SqlDataSource1.SelectCommand = "SELECT * FROM MAIN WHERE FIRSTNAME like '%" & TextBox1.Text & "%' and secondname like '%" & TextBox2.Text & "%'"

        SqlDataSource1.DataBind()

    End Sub

Open in new window

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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