Solved

How to filter asp.net gridview rows/columns

Posted on 2011-03-04
6
1,144 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

930 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

11 Experts available now in Live!

Get 1:1 Help Now