Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-10-24
3
2,967 Views
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">
<Columns>
	<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">
		<EditItemTemplate>
		<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Action_Item") %>' 		TextMode="MultiLine"></asp:TextBox>
		</EditItemTemplate>
		<ItemTemplate>
		<asp:Label ID="Label2" runat="server" Text='<%# Bind("Action_Item") %>'></asp:Label>
		</ItemTemplate>
		<ItemStyle VerticalAlign="Top" Wrap="True" />
	</asp:TemplateField>
	<asp:TemplateField HeaderText="Action Status" SortExpression="Action_Status">
		<EditItemTemplate>
		<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Action_Status") 		%>' TextMode="MultiLine"></asp:TextBox>
		</EditItemTemplate>
		<ItemTemplate>
		<asp:Label ID="Label1" runat="server" Text='<%# Bind("Action_Status") 		%>'></asp:Label>
		</ItemTemplate>
		<ItemStyle VerticalAlign="Top" Wrap="True" />
	</asp:TemplateField>
	<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" 	ReadOnly="True">
	<ItemStyle VerticalAlign="Top" />
	</asp:BoundField>
	<asp:TemplateField HeaderText="Action Owner" SortExpression="Action_Owner">
	<EditItemTemplate>
	<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:DropDownList>
	<asp:SqlDataSource ID="sdsCeva_Owner" runat="server" ConnectionString="<%$ 	ConnectionStrings:BusDevConnectionString %>" SelectCommand="View_Ceva_Owner_DD" 	SelectCommandType="StoredProcedure"></asp:SqlDataSource>
	</EditItemTemplate>
	<ItemTemplate>
	<asp:Label ID="lblActionOwner" runat="server" Text='<%# Bind("Action_Owner") 	%>'></asp:Label>
	</ItemTemplate>
	</asp:TemplateField>
	<asp:CheckBoxField DataField="Action_Closed" HeaderText="Closed" 	SortExpression="Action_Closed" />
	</Columns>
<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:GridView>
<asp:SqlDataSource ID="sdsgvActions" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>" SelectCommand="View_Opportunity_Actions_GV" SelectCommandType="StoredProcedure" UpdateCommand="Update_Opportunity_Actions_GV" UpdateCommandType="StoredProcedure">
<SelectParameters>
  	<asp:QueryStringParameter Name="Pir_Key" QueryStringField="Key" Type="Int32" />
</SelectParameters>
<UpdateParameters>
 	<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" />
</UpdateParameters>
</asp:SqlDataSource>

Open in new window

0
Comment
Question by:JessyRobinson1234
3 Comments
 
LVL 22

Expert Comment

by:prairiedog
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?
0
 
LVL 37

Expert Comment

by:samtran0331
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.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx
If you scroll down, there are examples in vb and c# that should easily fit into your code.

0
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 22809717
Hi,
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" />
</asp:BoundFiled>
 
.HiddenColumn
{
         display:none;
}

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

Hope this helps.
-M3mph15
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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