How can I hide a boundfield in Gridview to Visible="false" and still make it work?

Posted on 2008-10-24
Last Modified: 2012-05-05
The code below works fine but I don't want to display the action_key label. When I change the attribute Visible="True" to false it no long works. Any alternatives?
<asp:GridView ID="gvActions" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataSourceID="sdsgvActions"  AllowPaging="True" AllowSorting="True">
	<asp:BoundField DataField="PIR_Key" HeaderText="PIR_Key" InsertVisible="False" 	SortExpression="PIR_Key" Visible="False" />
	<asp:BoundField DataField="Action_Key"  HeaderText="Key" InsertVisible="False" 
                                    Visible="True"    />
	<asp:TemplateField HeaderText="Action Item" SortExpression="Action_Item">
		<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Action_Item") %>' 		TextMode="MultiLine"></asp:TextBox>
		<asp:Label ID="Label2" runat="server" Text='<%# Bind("Action_Item") %>'></asp:Label>
		<ItemStyle VerticalAlign="Top" Wrap="True" />
	<asp:TemplateField HeaderText="Action Status" SortExpression="Action_Status">
		<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Action_Status") 		%>' TextMode="MultiLine"></asp:TextBox>
		<asp:Label ID="Label1" runat="server" Text='<%# Bind("Action_Status") 		%>'></asp:Label>
		<ItemStyle VerticalAlign="Top" Wrap="True" />
	<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" 	ReadOnly="True">
	<ItemStyle VerticalAlign="Top" />
	<asp:TemplateField HeaderText="Action Owner" SortExpression="Action_Owner">
	<asp:DropDownList ID="ddlCeva_owner" runat="server" DataSourceID="sdsCeva_Owner"
	DataTextField="Ceva_Owner_Name" DataValueField="Ceva_Owner_Name" SelectedValue='<%# 	Bind("Ceva_Owner_Name") %>' CssClass="form">
	<asp:SqlDataSource ID="sdsCeva_Owner" runat="server" ConnectionString="<%$ 	ConnectionStrings:BusDevConnectionString %>" SelectCommand="View_Ceva_Owner_DD" 	SelectCommandType="StoredProcedure"></asp:SqlDataSource>
	<asp:Label ID="lblActionOwner" runat="server" Text='<%# Bind("Action_Owner") 	%>'></asp:Label>
	<asp:CheckBoxField DataField="Action_Closed" HeaderText="Closed" 	SortExpression="Action_Closed" />
<FooterStyle BackColor="#CCCC99" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<RowStyle BackColor="#F7F7DE" />
<AlternatingRowStyle BackColor="White" />
<asp:SqlDataSource ID="sdsgvActions" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>" SelectCommand="View_Opportunity_Actions_GV" SelectCommandType="StoredProcedure" UpdateCommand="Update_Opportunity_Actions_GV" UpdateCommandType="StoredProcedure">
  	<asp:QueryStringParameter Name="Pir_Key" QueryStringField="Key" Type="Int32" />
 	<asp:Parameter Name="Action_Item" Type="String" />
 	<asp:Parameter Name="Action_Status" Type="String" />
 	<asp:Parameter Name="Ceva_Owner_Name" Type="String" />
 	<asp:Parameter Name="Action_Key" Type="Int32" />

Open in new window

Question by:JessyRobinson1234
LVL 22

Expert Comment

ID: 22798855
>>> it no long works.
This does not help us. What do you mean exactly "it no longer works." Any error or something else?
LVL 37

Expert Comment

ID: 22799503
I would assume from the code posted that Action_Key is the primary key that the update is using.
So by "no long[er] works" I would imagine your update doesn't have anything to key off of.

If you want to not show the field, but still use it, the Gridview has a feature called DataKeys specifically made for this purpose.
If you scroll down, there are examples in vb and c# that should easily fit into your code.


Accepted Solution

M3mph15 earned 500 total points
ID: 22809717
I'm going to guess that "not working" means that you can't access the text etc. What you should do is set the CssClass="HiddenColumn".
<asp:BoundField DataField="Action_Key"  HeaderText="Key" InsertVisible="False" >
<HeaderStyle CssClass="HiddenColumn" />
<ItemStyle CssClass="HiddenColumn" />

This will hide the column but you will still be able to access the text of the cell etc.

Hope this helps.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question