Click here to Skip to main content
14,539,375 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need to hide the first row of a details view but the details view has a key dataitem which is read by another part of the code. when I try to go into the ASP side and select visible = false inside the row, the code behind no longer calls that data. the code is as follows:
<asp:detailsview ID="" runat="server" datakeynames="BICID">
     <fields>
          <asp:boundfield datafield="BICID" Headetertext="BICID"        

          SortExpression="BICID" Visible="false"/>
     </fields>


The BICID is the key data item that the following code is pulling:

protected void submitbttn_click(object sender, eventargs e)
{
     String bicidstring = detailsview1.rows[0].cells[1].text;
}


This code worked before setting the row visible to false, is there anyway to hide that row and the code behind still work?
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can try setting InsertVisible="False" ReadOnly="True"
This will hide the item while in insert mode, and read only in edit mode.
   
Comments
Sean8084 14-Oct-11 0:03am
   
but it doesn't need to be visible at all, and there is no insert or edit modes, there's a text box in the detailsview that I use for the update (along with a separate button for submit)
Rate this:
Please Sign up or sign in to vote.

Solution 2

That's right. Once you have set a row invisible or a control inside a DetailsView or any other View control, that control is no longer visible to neither the user nor the code behind. That's ASP.net for you!
You have to programmatically hide the row in code behind AFTER you've loaded the data into the DetailsView.
I suggest you place an OnDataBound() control on the DetailsView and use a simple
detailsview1.rows[0].visible = false;

or
DetailsView1.Fields[1].Visible = false;

to hide the row, but again AFTER you've got the data and placed it into a global variable that can be later used in your click event.
The only other way I can think of is for you to make that row invisible to the user by making the forecolor and backcolor the same.
Also consider using
Style.Add("display","none");
I found this works sometimes when you cannot use the Visible property.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100