L
landesjoe
Hi,
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
forth.
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
blank.
EnableViewState is set to True for the form, Gridview and text box.
Got any suggestions?
Thanks,
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"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Use" InsertVisible="False">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server"
AutoPostBack="True" CausesValidation="True"
OnCheckedChanged="chkSelected_CheckedChanged" / </ItemTemplate>
</asp:TemplateField>
<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:BoundField>
<asp:TemplateField HeaderText="Qty Returnable">
<EditItemTemplate>
<asp:TextBox ID="txtQtyToRA" runat="server" Text='<
%# Eval("QtyToRA") %>' Width="40px"></asp:TextBox>
</EditItemTemplate>
<ControlStyle Width="20px" />
<ItemTemplate>
<asp:TextBox ID="txtQtyToRA" runat="server"
MaxLength="4" Text='<%# Eval("QtyToRA") %>'
Width="40px"></asp:TextBox>
<asp:RangeValidator ID="rgvQtyToRA" runat="server"
ControlToValidate="txtQtyToRA"
MinimumValue="0" MaximumValue='<%#
Eval("QtyShipped") %>' Type="Integer" Display="Dynamic"></
asp:RangeValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ShipFrom" HeaderText="Ship
From" ReadOnly="True" />
<asp:TemplateField HeaderText="Return Reason">
<ItemTemplate>
<aspropDownList ID="cboRAReason" runat="server"
Width="170px">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
not this way<br />
<br />
</PagerTemplate>
<AlternatingRowStyle BackColor="#FFFFC0" />
</asp:GridView>
Here's the event handler:
Protected Sub chkSelected_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
' Check status of ctonrols
CheckControlStatus()
gvItems.Columns(6).Visible = Not gvItems.Columns(6).Visible
End Sub
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
forth.
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
blank.
EnableViewState is set to True for the form, Gridview and text box.
Got any suggestions?
Thanks,
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"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Use" InsertVisible="False">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server"
AutoPostBack="True" CausesValidation="True"
OnCheckedChanged="chkSelected_CheckedChanged" / </ItemTemplate>
</asp:TemplateField>
<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:BoundField>
<asp:TemplateField HeaderText="Qty Returnable">
<EditItemTemplate>
<asp:TextBox ID="txtQtyToRA" runat="server" Text='<
%# Eval("QtyToRA") %>' Width="40px"></asp:TextBox>
</EditItemTemplate>
<ControlStyle Width="20px" />
<ItemTemplate>
<asp:TextBox ID="txtQtyToRA" runat="server"
MaxLength="4" Text='<%# Eval("QtyToRA") %>'
Width="40px"></asp:TextBox>
<asp:RangeValidator ID="rgvQtyToRA" runat="server"
ControlToValidate="txtQtyToRA"
MinimumValue="0" MaximumValue='<%#
Eval("QtyShipped") %>' Type="Integer" Display="Dynamic"></
asp:RangeValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ShipFrom" HeaderText="Ship
From" ReadOnly="True" />
<asp:TemplateField HeaderText="Return Reason">
<ItemTemplate>
<aspropDownList ID="cboRAReason" runat="server"
Width="170px">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
not this way<br />
<br />
</PagerTemplate>
<AlternatingRowStyle BackColor="#FFFFC0" />
</asp:GridView>
Here's the event handler:
Protected Sub chkSelected_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
' Check status of ctonrols
CheckControlStatus()
gvItems.Columns(6).Visible = Not gvItems.Columns(6).Visible
End Sub