473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

Hello,

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.Visible = False;
- The SHOW button makes GridView.Visible = 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,
Miguel

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

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_Build()

' Set gvProfessor properties
With gvProfessor
.AllowPaging = False
.AutoGenerateColumns = False
.BorderColor = Drawing.ColorTranslator.FromHtml("#FFFFFF")
.BorderStyle = BorderStyle.Solid
.BorderWidth = Unit.Pixel(1)
.CellPadding = 1
.CssClass = "gvProfessor"
.GridLines = GridLines.Horizontal
.ShowFooter = True
.ShowHeader = True
.Width = Unit.Pixel(320)
End With

' Add description template column to gvProfessor
Dim tfDescription As New TemplateField
tfDescription.ItemTemplate = New
gvtDescricao(DataControlRowType.DataRow, "description")
gvProfessor.Columns.Add(tfDescription)

' Add icon template column to gvProfessor
Dim tfIcon As New TemplateField
tfIcon.ItemTemplate = New gvtDescricao(DataControlRowType.DataRow,
"icon")
gvProfessor.Columns.Add(tfIcon)

' Set gvProfessor icon column width
gvProfessor.Columns(1).ItemStyle.Width = Unit.Pixel(22)

' Create dtProfessor
Dim dtProfessor As New DataTable
dtProfessor.Columns.Add("description", GetType(String))
dtProfessor.Columns.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.Rows.Add(New Object() {"<h1 class='gvProfessor'>" &
rows(iRow, 0) & "</h1>" & _
"<p class='gvProfessor'>" &
rows(iRow, 1) & "</p>", rows(iRow, 2)})
Next iRow

' Create dsProfessor
Dim dsProfessor As New DataSet
dsProfessor.Tables.Add(dtProfessor)

' Bind gvProfessor
gvProfessor.DataSource = dsProfessor
gvProfessor.DataBind()

' Create gvProfessor header
Dim iHeader As New Image
With iHeader
.AlternateText =
Me.GetLocalResourceObject("iProfessor_GvHeader.Alt ernateText")
.CssClass = "iProfessor_GvHeader"
.ID = "iProfessor_GvHeader"
.ImageUrl = "~/Assets/Design/Images/Professor_GvHeader.jpg"
.ToolTip =
Me.GetLocalResourceObject("iProfessor_GvHeader.Too lTip")
End With
gvProfessor.HeaderRow.Cells(0).Controls.Add(iHeade r)

' Create gvProfessor footer
Dim iFooter As New Image
With iFooter
.AlternateText =
Me.GetLocalResourceObject("iProfessor_GvFooter.Alt ernateText")
.CssClass = "iProfessor_GvFooter"
.ID = "iProfessor_GvFooter"
.ImageUrl = "~/Assets/Design/Images/Professor_GvFooter.jpg"
.ToolTip =
Me.GetLocalResourceObject("iProfessor_GvFooter.Too lTip")
End With
gvProfessor.FooterRow.Cells(0).Controls.Add(iFoote r)

End Sub

-- Class which creates the Item Template --

' gvtDescricao
Public Class gvtDescricao
Implements ITemplate

Private templateType As DataControlRowType
Private dataColumn As String

Sub New(ByVal type As DataControlRowType, ByVal column As String)

templateType = type
dataColumn = column

End Sub

Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements
ITemplate.InstantiateIn

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

Case DataControlRowType.Header

' ---

Case DataControlRowType.DataRow

Select Case dataColumn
Case "description"

' 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
binding.
AddHandler lDescription.DataBinding, AddressOf
Description_DataBinding

' Add the control to the controls collection of the
container.
container.Controls.Add(lDescription)

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
binding.
AddHandler iIcon.DataBinding, AddressOf Icon_DataBinding

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

End Select

Case Else

' Insert code to handle unexpected values.

End Select

End Sub

Private Sub Description_DataBinding(ByVal sender As Object, ByVal e As
EventArgs)

' 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(lDescription.NamingContainer,
GridViewRow)

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

End Sub

Private Sub Icon_DataBinding(ByVal sender As Object, ByVal e As
EventArgs)

' 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.NamingContainer, 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 9327
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
rendered.

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.getElementById("MyGrid").style.display = "none";
}

function showGrid()
{
document.getElementById("MyGrid").style.display = "block";
}
</script>

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

<INPUT Type="button" Value="Show" OnClick="showGrid()"> <br/>
<INPUT Type="button" Value="Hide" OnClick="hideGrid()">

-Carl

Feb 22 '06 #2

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

Similar topics

6
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...
3
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...
6
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...
14
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...
2
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...
7
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...
2
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...
2
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

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.