Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview text box column loses value after changing .Visible property

Thread Tools

Gridview text box column loses value after changing .Visible property
Posts: n/a
here's my problem in short: Text boxes in gridview don't seem to hold
their value if the column's .Visible property is changed back and

I've got a form with a gridview populated from a data view (which in
turn is loaded from a manually setup DataTable for testing purposes).
One of the columns in the grid is a checkbox that's tied to an event
handler that'll change the .Visible property of a column with a text
box. That text box column (column 6 in the example code below)
initially has a numeric value, but after hiding and showing again is
EnableViewState is set to True for the form, Gridview and text box.

Got any suggestions?

Joe Landes

ASP code to setup the control:
<asp:GridView ID="gvItems" runat="server" Height="59px"
Width="662px" Style="left: 17px;
position: relative; top: -1px" AllowSorting="True"
<asp:TemplateField HeaderText="Use" InsertVisible="False">
<asp:CheckBox ID="chkSelected" runat="server"
AutoPostBack="True" CausesValidation="True"
OnCheckedChanged="chkSelected_CheckedChanged" /

<asp:HyperLinkField HeaderText="Order #"
DataTextField="OrderNum" NavigateUrl="~/Login.aspx" />
<asp:BoundField DataField="OrderID" HeaderText="OEM #"
ReadOnly="True" />
<asp:BoundField DataField="UnitPrice"
DataFormatString="${0:C2}" HeaderText="Price"
ReadOnly="True" HtmlEncode="False" />
<asp:BoundField DataField="UnitCost"
DataFormatString="{0:c2}" HeaderText="Cost"
HtmlEncode="False" />
<asp:BoundField DataField="QtyShipped" HeaderText="Qty
Shipped" ReadOnly="True">
<ControlStyle Width="20px" />
<asp:TemplateField HeaderText="Qty Returnable">
<asp:TextBox ID="txtQtyToRA" runat="server" Text='<
%# Eval("QtyToRA") %>' Width="40px"></asp:TextBox>
<ControlStyle Width="20px" />
<asp:TextBox ID="txtQtyToRA" runat="server"
MaxLength="4" Text='<%# Eval("QtyToRA") %>'
<asp:RangeValidator ID="rgvQtyToRA" runat="server"
MinimumValue="0" MaximumValue='<%#
Eval("QtyShipped") %>' Type="Integer" Display="Dynamic"></
<asp:BoundField DataField="ShipFrom" HeaderText="Ship
From" ReadOnly="True" />
<asp:TemplateField HeaderText="Return Reason">
<aspropDownList ID="cboRAReason" runat="server"
not this way<br />
<br />
<AlternatingRowStyle BackColor="#FFFFC0" />

Here's the event handler:
Protected Sub chkSelected_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
' Check status of ctonrols
gvItems.Columns(6).Visible = Not gvItems.Columns(6).Visible
End Sub

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net 0 04-12-2007 03:11 PM
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net Web Controls 0 04-12-2007 02:40 PM
How to hide a GridView column when the column's Visible property does not support databinding? Keithb ASP .Net 2 10-27-2006 05:02 AM
Text Box Loses Value On Page Load =?Utf-8?B?Q2xheXRvbiBIb3l0?= ASP .Net 1 02-03-2006 02:12 AM
DataGrid loses view state if first column is a template column. Ken Varn ASP .Net 1 08-19-2005 02:54 PM