By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,077 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,077 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.