How to hide template field in GridView in VB.Net?

Hi,

   I have a template field in gridview.

  The template field is textbox.This template field is bound to a datafield.

  I am binding data to the grid.

  I need to have "100" in all textboxes when that textbox is visible.

 I need this textbox to be invisible in some  rows and visible in some rows.

 How to make the textbox invisible /visible while binding data to the gridview.

 Please help in this.

 Thanks a lot inadvance!!!

 


Lokanadham M.
Hyderabad.
0
lokanadham
2/26/2008 10:45:07 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
1485 Views

Similar Articles

[PageSpeed] 2

GridView.Column[0].Visible =  false 

 


Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
0
vik20000in
2/26/2008 11:21:41 AM



Hey lokanadham,


Its not clear to me yet, but I think it can be done @GridView1_RowDataBound event

can you tell me when do you want the template field visible = false and when to be true ?

 

Best regards ...


Please, “Mark as Answer” the post that helped you.
0
XGmarX
2/26/2008 11:34:38 AM

Hi,

   Thanks for your quick reply!!!

   This is to hide the entire column of a gridview.

   I want to hide some of the textboxes in that column  visible and some invisible.

  This need to be done while data is bound to the gridview.


Lokanadham M.
Hyderabad.
0
lokanadham
2/26/2008 11:34:51 AM

Hi XGmarX

     Thanks for your quick reply!!!

     I have a textbox in template field of grid view.This textbox has datafield("datafield for textbox") bound to it.

    while binding data to the textbox what I am doing is

  datatable.columns.add("Someother  field")

      datatable.columns.add("datafield for textbox")

     datatable.rows.add(''Hi","20")

     datatable.rows.add("Ji","30")

     When I write code like this,I am getting  20 and 30 in those textboxes.

     I do not need to have the second textbox.It should be invisible.

    It should be done while binding it to the gridview

     I


Lokanadham M.
Hyderabad.
0
lokanadham
2/26/2008 11:40:57 AM

If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Or e.Row.RowType = ListItemType.EditItem Then

Dim txtname As textbox = CType(e.Row.FindControl("textboxId"), textbox)

(you can implement any condition here) 

txtname.visible =false 

End If


Click "Mark as answer" when it helps
0
sarjoun
2/26/2008 12:02:14 PM



Hey lokanadham,


Please, do the following :

For Each dr As GridViewRow In GridView1.Rows

Dim tb As TextBox = DirectCast(dr.Controls(3).FindControl("TextBox1"), TextBox)

If Integer.Parse(tb.Text) != 100 Then

tb = DirectCast(dr.Controls(3).FindControl("TextBox1"), TextBox)

tb.Visible = False

Else

tb = DirectCast(dr.Cells(3).FindControl("TextBox1"), TextBox)

tb.Visible = True

End If

Next

 

This is to be done @GridView1_RowDataBound event


Please, let me know if that helped ...


Please, “Mark as Answer” the post that helped you.
0
XGmarX
2/26/2008 12:24:32 PM

lokanadham:

 I need this textbox to be invisible in some  rows and visible in some rows.

 How to make the textbox invisible /visible while binding data to the gridview.


Hi lokanadham,

If you wanted to Hide certain controls inside your GridView then use FindControl Method to achieve that in RowDatabound event something like

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim tb As TextBox = DirectCast(e.Row.Cells(0).FindControl("TextBox1"), TextBox)   ' Just change the index of cells based on your requirements
        tb.Visible = False
    End If
End Sub 

 

Hope it helps! 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/26/2008 1:09:11 PM

Hi All,

Thanks alot for your replies.

As you all said,this works fine.

But here we are making visible or invisible after binding the data.

I want it to be done while binding.

It should be like when rows are added to the table,I should be able to make them invisible.

Can we do like,

datatable.rows.add("",true)

datatable.rows.add("",false)

where true means textbox is visible and false means invisible,Can we do like this??????

This is what actually I need..

Thanks alot all


Lokanadham M.
Hyderabad.
0
lokanadham
2/26/2008 2:30:09 PM

lokanadham:

I want it to be done while binding.

It should be like when rows are added to the table,I should be able to make them invisible.

Why not just dont add the Items in the DataTable if you dont want to show it in the Grid and ONLY add those items that you wanted to show.. because i dont think if you can hide or show the data from the datatable...


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/26/2008 2:47:50 PM
Reply:

Web resources about - How to hide template field in GridView in VB.Net? - asp.net.presentation-controls

Template - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Facebook page template & tips for 2014
As Facebook page admins get started with 2014, the social marketing experts at ShortStack created a detailed template , including image sizes, ...

Frame Artist Pro - Best Photo Collage Editor, Stitch Your Photos with Pic Frame Templates & Filter Effect ...
Get Frame Artist Pro - Best Photo Collage Editor, Stitch Your Photos with Pic Frame Templates & Filter Effect & Frames on the App Store. See ...

Paper wireframe templates - Flickr - Photo Sharing!
jasonrobb.com/v2/i/Wireframe-templates-JasonRobb.zip jasonrobb.com

United Airlines accidentally sends letter template to unhappy passenger
A US air passenger may have received what is quite possibly the world’s least sincere apology letter.

TV Templates - Transcripts
Lorem ipsum dolor sit amet, aihiad adaph dpas, osaf das. Oi asdfpo ijafj ai.

Mockup Apple Watch apps and compare screen sizes with these official bezel templates
... for developers, readers interested in Apple Watch can also use the images to compare the overall physical size of the two sizes. The templates ...

Paper by FiftyThree makes starting new projects easier with templates
... FiftyThree has just received an update that significantly improves various aspects of its interface and functionality. Get started with templates ...

Windows 10 patch messing with your Office 2016 templates? Here's how you can get them back
... 10 patch has had some Word 2016 users cringing in despair. The patch, titled Cumulative Update KB3124200 , is causing the Word 2016 template ...

Templates, Insights and Dictation in Google Docs
Google's standalone web apps for Docs , Sheets and Slides now show a list of templates you can choose to quickly create a document, spreadsheet ...

Resources last updated: 1/14/2016 6:45:11 PM