Solved

How to filter asp.net gridview rows/columns

Posted on 2011-03-04
6
1,143 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now