Click here to Skip to main content
15,885,985 members
Articles / Web Development / ASP.NET
Tip/Trick

Find Text Inside Gridivew Cell

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
3 Jul 2010CPOL 19.6K   134   2   3
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:

VB.NET
 //
 // 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:

VB.NET
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Nepal Nepal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralA Tip/Trick!!! Pin
Sandeep Mewara3-Jul-10 20:48
mveSandeep Mewara3-Jul-10 20:48 
GeneralComments Pin
Md. Marufuzzaman3-Jul-10 20:24
professionalMd. Marufuzzaman3-Jul-10 20:24 
GeneralNot an article Pin
#realJSOP3-Jul-10 11:51
mve#realJSOP3-Jul-10 11:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.