Solved

How to filter asp.net gridview rows/columns

Posted on 2011-03-04
6
1,151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 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