Hi,
I have a GridView that has one column that I fill with an alternating "Title
Row" then "Details Row". The Title row has a button that I use to hide it's
corresponding details row that is underneath it for users to collapse detail
rows leaving the title row visible. The button can be clicked again to show
the details.
This used to work great using a DataGrid but when I upgraded it to a
GridView I experience the following problem:
When clicking the button it hides the details row as expected but when
clicking other buttons, the previously hidden details row show. They do not
retain their hidden attributes.
Can someone help me with this? THANKS!
Here's the code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" ShowHeader="false"
OnRowCommand="GridView1_RowCommand" Width="100%"
EnableViewState="true">
<Columns>
<asp:ButtonField ButtonType="Button"
CommandName="btnCollapse" Text="-">
<ControlStyle Font-Size="XX-Small" Height="18px"
Width="18px" />
<ItemStyle VerticalAlign="Top" />
</asp:ButtonField>
<asp:BoundField DataField="Logs" HtmlEncode="False">
<ItemStyle VerticalAlign="Top" Wrap="True" />
</asp:BoundField>
</Columns>
<EmptyDataRowStyle Height="40px" />
<HeaderStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="Transparent" />
<RowStyle BackColor="Gainsboro" />
</asp:GridView>
</div>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Call FillGridView()
End Sub
Private Sub FillGridView()
Dim j As Short
Dim dt As New DataTable
dt.Columns.Add("Logs", GetType(System.String))
For j = 1 To 5
Dim dr1 As DataRow = dt.NewRow
dr1(0) = "Title " & j.ToString
dt.Rows.Add(dr1)
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Details here ..."
dt.Rows.Add(dr2)
Next
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Call CleanUpButtons(Me.GridView1)
End Sub
Private Sub CleanUpButtons(ByVal gv As GridView)
Dim j As Integer
Try
For j = 1 To gv.Rows.Count Step 2
gv.Rows(j).Cells(0).Controls(0).Visible = False
Next
Catch ex As System.Exception
j = 0
End Try
End Sub
Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
GridViewCommandEventArgs)
Dim i As Integer = Convert.ToInt32(e.CommandArgument)
Dim iSelectedRow As GridViewRow = Me.GridView1.Rows(i)
Dim iDetailsRow As GridViewRow = Me.GridView1.Rows(i + 1)
Dim btn As Button = iSelectedRow.Cells(0).Controls(0)
If btn.Text = "-" Then
iDetailsRow.Visible = False
btn.Text = "+"
Else
iDetailsRow.Visible = True
btn.Text = "-"
End If
End Sub
End Class
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
<add namespace="System.Data"/>
</namespaces>
</pages>
<authentication mode="Windows"/>
</system.web>
</configuration> 3 2252
Can someone test this code and give me some pointers?
Thank you very much!
"sharris12345" wrote:
Hi,
I have a GridView that has one column that I fill with an alternating "Title
Row" then "Details Row". The Title row has a button that I use to hide it's
corresponding details row that is underneath it for users to collapse detail
rows leaving the title row visible. The button can be clicked again to show
the details.
This used to work great using a DataGrid but when I upgraded it to a
GridView I experience the following problem:
When clicking the button it hides the details row as expected but when
clicking other buttons, the previously hidden details row show. They do not
retain their hidden attributes.
Can someone help me with this? THANKS!
Here's the code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" ShowHeader="false"
OnRowCommand="GridView1_RowCommand" Width="100%"
EnableViewState="true">
<Columns>
<asp:ButtonField ButtonType="Button"
CommandName="btnCollapse" Text="-">
<ControlStyle Font-Size="XX-Small" Height="18px"
Width="18px" />
<ItemStyle VerticalAlign="Top" />
</asp:ButtonField>
<asp:BoundField DataField="Logs" HtmlEncode="False">
<ItemStyle VerticalAlign="Top" Wrap="True" />
</asp:BoundField>
</Columns>
<EmptyDataRowStyle Height="40px" />
<HeaderStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="Transparent" />
<RowStyle BackColor="Gainsboro" />
</asp:GridView>
</div>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Call FillGridView()
End Sub
Private Sub FillGridView()
Dim j As Short
Dim dt As New DataTable
dt.Columns.Add("Logs", GetType(System.String))
For j = 1 To 5
Dim dr1 As DataRow = dt.NewRow
dr1(0) = "Title " & j.ToString
dt.Rows.Add(dr1)
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Details here ..."
dt.Rows.Add(dr2)
Next
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Call CleanUpButtons(Me.GridView1)
End Sub
Private Sub CleanUpButtons(ByVal gv As GridView)
Dim j As Integer
Try
For j = 1 To gv.Rows.Count Step 2
gv.Rows(j).Cells(0).Controls(0).Visible = False
Next
Catch ex As System.Exception
j = 0
End Try
End Sub
Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
GridViewCommandEventArgs)
Dim i As Integer = Convert.ToInt32(e.CommandArgument)
Dim iSelectedRow As GridViewRow = Me.GridView1.Rows(i)
Dim iDetailsRow As GridViewRow = Me.GridView1.Rows(i + 1)
Dim btn As Button = iSelectedRow.Cells(0).Controls(0)
If btn.Text = "-" Then
iDetailsRow.Visible = False
btn.Text = "+"
Else
iDetailsRow.Visible = True
btn.Text = "-"
End If
End Sub
End Class
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
<add namespace="System.Data"/>
</namespaces>
</pages>
<authentication mode="Windows"/>
</system.web>
</configuration>
Hi sharris,
I haven't tried your code, but from looking at it, it makes sense -
you're binding the grdiview in every Page_Load which causes it to
re-create each row and therefore "forget" about the Visible information.
Try to only bind the GridView in the Page_Load if it is not a postback
request.
Hope this helps,
Cheers,
Roland
sharris12345 schrieb:
>Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Call FillGridView()
(.. the sub FillGridView does a DataBind)
Thank you very much.
That was it.
Now I'm really embarrassed for my post!
"Roland Dick" wrote:
Hi sharris,
I haven't tried your code, but from looking at it, it makes sense -
you're binding the grdiview in every Page_Load which causes it to
re-create each row and therefore "forget" about the Visible information.
Try to only bind the GridView in the Page_Load if it is not a postback
request.
Hope this helps,
Cheers,
Roland
sharris12345 schrieb:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Call FillGridView()
(.. the sub FillGridView does a DataBind) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martin B |
last post by:
Hallo to everyone!
Problem:
--------
GridView Exception: reentrant call to the SetCurrentCellAddressCore function
System:
-------
WinXP Professional, english, .NET Framework 2.0 Beta...
|
by: NateDawg |
last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if
anyone has some input it would sure help me out.
Ok, I’ve noticed a few gridview problems floating around the forum....
|
by: guanfenglin |
last post by:
Hello,
I have a grid view which display and updates the data, however it
doesn't work well, I always either get invalid name/number or not all
varaibles bound, I am very frustrated at the...
|
by: Jeff |
last post by:
Hey
asp.net 2.0
In the source I posted below, there is a GridView (look at the bottom of the
script):
<asp:GridView ID="gvwOnline" runat="server">
</asp:GridView>
I'm trying to assign a...
|
by: Tomasz Jastrzebski |
last post by:
Helo All,
The problem: GridView control does not render at all (header/footer) when
the data source is empty.
I have seen a similar question posted already, but I just can not believe
there is...
| |
by: antonyliu2002 |
last post by:
I've been googling for some time, and could not find the solution to
this problem.
I am testing the paging feature of gridview. I have a very simple web
form on which the user can select a few...
|
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...
|
by: RobertTheProgrammer |
last post by:
Hi all,
I'm really stuck here. I've got a GridView on my page and I want to use the update features to-- well, update. Here is my block of code in the SqlDataSource section:
...
|
by: RobertTheProgrammer |
last post by:
Hi folks,
Here's a weird problem...
I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
|
by: Ananthu |
last post by:
I have created a templatefield at runtime for checkboxcolumn in gridview using Itemplate Interface and InstanceIn methods.
I have given the id for checkbox also.
I get the checkbox column in...
|
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,...
| |
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,...
|
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
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...
| |