Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Find Text Inside Gridivew Cell

0.00/5 (No votes)
3 Jul 2010 1  
Get the text present inside tablecell in both visible or hidden mode using VB.NET

Introduction

This article is used to demonstrate to the user how to get the text present on TableCell inside a GridView. The basic idea is bind your datavalue inside a server side control and finally search for the control and get text from it. The process I have shown is also for a case when a particular column is hidden.

Using the Code

In this sample application, there are two buttons, a button for finding text at column "Data Text" and a button that shows/hides data present under header "Name" and "Data Text".

The button for show/hide certain columns has the following click() event:

 //
 // Button click event for show/hide columns.
 //
        
Protected Sub btnShowHide_Click(ByVal sender As Object, _
	ByVal e As System.EventArgs) Handles btnShowHide.Click
 gvPopulate.Columns(0).Visible = Not gvPopulate.Columns(0).Visible
 gvPopulate.Columns(2).Visible = Not gvPopulate.Columns(2).Visible
End Sub

Similarly, the button for finding the text present inside a cell have the following click() event:

Dim myText As String = String.Empty
For Each row As GridViewRow In gvPopulate.Rows
    Dim chkSelect As CheckBox = CType(row.FindControl("chkSelectName"), CheckBox)
    If chkSelect.Checked Then
        myText &= CType(row.FindControl("ltrDataText"), Literal).Text & " "
    End If
Next
If myText <> String.Empty Then
    ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType(), _
	"message", "alert('" & myText & "');", True)
End If

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here