Solved

How to filter asp.net gridview rows/columns

Posted on 2011-03-04
6
1,147 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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