473,839 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with making GridView Visble and Invisible. I am on this for 1 week. Need help. Thank You.


I have a GridView in my page which is created in runtime. It works fine.

My page has 2 Asp Buttons:
- The HIDE button makes GridView.Visibl e = False;
- The SHOW button makes GridView.Visibl e = True.

I press HIDE and the GridView disappears as expected.
After it I press SHOW and the GridView doesn't show.

In fact it shows because I can see the GridLines separating the right
number of rows.

However, I can't see any row content, header or footer.

My GridView is composed by:
- An asp image control in the header row and in the footer row;
- An asp label and image in a template field.

I am trying to figure this out for 1 week.
I tried everything I could think of.

It doesn't make any sense to me that tha grid controls don't show up
when I press SHOW after I hidded the grid.

Can someone please help me out?

Thank You,

I am creating my View Grid using the ItemTemplate contructor as in MSDN

I add the function which creates the GridView and the Class which i use
to create the ItemTemplate:

-- Function that creates the GridView ---

Private Sub gvProfessor_Bui ld()

' Set gvProfessor properties
With gvProfessor
.AllowPaging = False
.AutoGenerateCo lumns = False
.BorderColor = Drawing.ColorTr anslator.FromHt ml("#FFFFFF")
.BorderStyle = BorderStyle.Sol id
.BorderWidth = Unit.Pixel(1)
.CellPadding = 1
.CssClass = "gvProfesso r"
.GridLines = GridLines.Horiz ontal
.ShowFooter = True
.ShowHeader = True
.Width = Unit.Pixel(320)
End With

' Add description template column to gvProfessor
Dim tfDescription As New TemplateField
tfDescription.I temTemplate = New
gvtDescricao(Da taControlRowTyp e.DataRow, "descriptio n")
gvProfessor.Col umns.Add(tfDesc ription)

' Add icon template column to gvProfessor
Dim tfIcon As New TemplateField
tfIcon.ItemTemp late = New gvtDescricao(Da taControlRowTyp e.DataRow,
gvProfessor.Col umns.Add(tfIcon )

' Set gvProfessor icon column width
gvProfessor.Col umns(1).ItemSty le.Width = Unit.Pixel(22)

' Create dtProfessor
Dim dtProfessor As New DataTable
dtProfessor.Col umns.Add("descr iption", GetType(String) )
dtProfessor.Col umns.Add("icon" , GetType(Boolean ))

' Create dtProfessor rows
Dim rows As Object(,) = {{"Disciplinas" , "Acesso a todas as
disciplinas", True}, _
{"Níveis de Ensino", "Acesso a todos os
níveis de ensino", True}, _
{"Documentos ", "Consulta, download e
impressão", True}, _
{"Foruns", "Acesso aos fóruns de dúvidas e
de discussão", True}, _
{"Artigos", "Consulta de artigos", True}, _
{"Newsletter ", "Subscrição da newsletter
BonsAlunos.com" , True}}

' Add rows to dtProfessor
Dim iRow As Integer
For iRow = 0 To rows.GetLength( 0) - 1
dtProfessor.Row s.Add(New Object() {"<h1 class='gvProfes sor'>" &
rows(iRow, 0) & "</h1>" & _
"<p class='gvProfes sor'>" &
rows(iRow, 1) & "</p>", rows(iRow, 2)})
Next iRow

' Create dsProfessor
Dim dsProfessor As New DataSet
dsProfessor.Tab les.Add(dtProfe ssor)

' Bind gvProfessor
gvProfessor.Dat aSource = dsProfessor
gvProfessor.Dat aBind()

' Create gvProfessor header
Dim iHeader As New Image
With iHeader
.AlternateText =
Me.GetLocalReso urceObject("iPr ofessor_GvHeade r.AlternateText ")
.CssClass = "iProfessor_GvH eader"
.ID = "iProfessor_GvH eader"
.ImageUrl = "~/Assets/Design/Images/Professor_GvHea der.jpg"
.ToolTip =
Me.GetLocalReso urceObject("iPr ofessor_GvHeade r.ToolTip")
End With
gvProfessor.Hea derRow.Cells(0) .Controls.Add(i Header)

' Create gvProfessor footer
Dim iFooter As New Image
With iFooter
.AlternateText =
Me.GetLocalReso urceObject("iPr ofessor_GvFoote r.AlternateText ")
.CssClass = "iProfessor_GvF ooter"
.ID = "iProfessor_GvF ooter"
.ImageUrl = "~/Assets/Design/Images/Professor_GvFoo ter.jpg"
.ToolTip =
Me.GetLocalReso urceObject("iPr ofessor_GvFoote r.ToolTip")
End With
gvProfessor.Foo terRow.Cells(0) .Controls.Add(i Footer)

End Sub

-- Class which creates the Item Template --

' gvtDescricao
Public Class gvtDescricao
Implements ITemplate

Private templateType As DataControlRowT ype
Private dataColumn As String

Sub New(ByVal type As DataControlRowT ype, ByVal column As String)

templateType = type
dataColumn = column

End Sub

Sub InstantiateIn(B yVal container As System.Web.UI.C ontrol) Implements
ITemplate.Insta ntiateIn

' Create the content for the different row types.
Select Case templateType

Case DataControlRowT ype.Header

' ---

Case DataControlRowT ype.DataRow

Select Case dataColumn
Case "descriptio n"

' Create the control to put in a data row section.
Dim lDescription As New Literal

' Set the control properties.
With lDescription
End With

' Register the event-handling methods to perform the data
AddHandler lDescription.Da taBinding, AddressOf
Description_Dat aBinding

' Add the control to the controls collection of the
container.Contr ols.Add(lDescri ption)

Case "icon"

' Create the control to put in a data row section.
Dim iIcon As New Image

' Set the control properties.
With iIcon
End With

' Register the event-handling methods to perform the data
AddHandler iIcon.DataBindi ng, AddressOf Icon_DataBindin g

' Add the control to the controls collection of the
container.Contr ols.Add(iIcon)

End Select

Case Else

' Insert code to handle unexpected values.

End Select

End Sub

Private Sub Description_Dat aBinding(ByVal sender As Object, ByVal e As

' Bind the lDescription label to GridView data source
Dim lDescription As Literal = CType(sender, Literal)

' Get the GridViewRow object that contains lDescription.
Dim row As GridViewRow = CType(lDescript ion.NamingConta iner,

' Get the field value from the GridViewRow object and assign it to
the Text property of the Literal control.
lDescription.Te xt = DataBinder.Eval (row.DataItem,
"description"). ToString()

End Sub

Private Sub Icon_DataBindin g(ByVal sender As Object, ByVal e As

' Bind the iIcon image to GridView data source
Dim iIcon As Image = CType(sender, Image)

' Get the GridViewRow object that contains lDescription.
Dim row As GridViewRow = CType(iIcon.Nam ingContainer, GridViewRow)

' Get the field value from the GridViewRow object and assign it to
the Text property of the Literal control.
With iIcon
.AlternateText = "Disponível "
.ImageUrl = "~/Assets/Design/Images/Verified_20x20_ Icon.jpg"
.ToolTip = "Disponível "
End With

End Sub

End Class

Feb 22 '06 #1
1 9362
I don't see the code where the Grid's visibility is being changed or
where the methods that create the grid are getting called. The problem
is probably related to when in the page's lifecycle the grid is being

I wouldn't bother with a server-side call to hide the grid though. A
quick client side script can do it much easier:

<script type="text/javascript">
function hideGrid()
document.getEle mentById("MyGri d").style.displ ay = "none";

function showGrid()
document.getEle mentById("MyGri d").style.displ ay = "block";

<div id="MyGrid">
<asp:GridView ...>

<INPUT Type="button" Value="Show" OnClick="showGr id()"> <br/>
<INPUT Type="button" Value="Hide" OnClick="hideGr id()">


Feb 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
by: John Daly | last post by:
I am using a Gridview to display a phone directory, with paging on. I have a link button that a user clicks to add a new record, which reloads the page, sets the visble property to false on the gridview and shows the form view in insert mode. Upon saving, the process is reversed. All is well and dandy, however I want to jump to the page that has the newly entered record, with the record highlighted. Does anyone know how to do this? I...
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In the RowDeleting event, I try to access the DataKeys property, but it contains no elements. This is the first time I'm trying to use DatKeyNames and DataKeys. What am I missing here?
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought I'll make the inactive forms invisible but this is creating a memory corruption problem when user close the form2 or form3 and not the formMain. My main form has a Next button which makes the main form invisible and starts a new form which I'll...
by: rgparkins | last post by:
So, I've bitten the bullet and am converting some of my asp.net 1.1 sites to asp.net 2.0, now after many issues I have come to a stop with the objectdatasource and gridviews and maybe someone can help! I have update, add adapter calls on the objectdatasource working well, however I have an issue with the delete call. In ASP.NET 2.0 I see that invisible columns are now no longer sent across in viewstate (something about security) and...
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
Is there a way to use a gridview in a timecard application, and if so, how? I was looking at using a gridview to display a person's hours worked in a week. To do this, many different data records would have to display on the same row to make up a week (the database has a new row for each day entered). But, from what I can tell, this keeps you from being able to use a gridview, because the gridview relies on one datakey per row (and there...
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
Based on wether a row is selected in a GridView I need to HIDE the last two columns of a gridview. I do NOT need to make the cells invisible I want to hide the entire column. When I set the Visible property on the columns it causes the underlying ObjectDataSource to re-issue the Select statement. How can I hide these columns without double clutching the ODS Select?
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two Panels represent a Master-Detail type relationship. I want a user to click a LinkButton in the first Panel and then for the 2nd Panel to be displayed with the detail. However, I need to set some text properties of textboxes programmatically when the...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.