0

Hello All,

I have a Web Application I am developing that has a GridView.
I have searched the internet to no avail looking for an answer to this.

The gridview has 11 columns. I want to hide the 11th column while in normal mode and make visible while in edit mode.

Here is my Code:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowState = DataControlRowState.Edit Then
GridView1.Columns(11).Visible = True

ElseIf e.Row.RowState = DataControlRowState.Normal Then
GridView1.Columns(11).Visible = False

End If
End Sub

My result from the above code is The 11th column is not visible in Normal mode but when I click the Edit button an error StackOverflowExceptionwasunhandled comes up.

What am I missing :-/

Edited by __avd: Added [code] tags.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by grafiksinc
0

I don't know if this will help, but I've done this prior to binding a dataset to a datagrid. this comes in handy if you have a situation where you want to re-use a dataset without re-quering the db. here's an example:

Case "DisplayResults"
                    DisplayResults.DataSource = resultsDataSet.Tables(0)
                    resultsDataSet.Tables(0).Columns.Remove("AGENT_FIRST")
                    resultsDataSet.Tables(0).Columns.Remove("AGENT_MID")
                    resultsDataSet.Tables(0).Columns.Remove("AGENT_LAST")
                    resultsDataSet.Tables(0).Columns.Remove("FileNo")
                    resultsDataSet.Tables(0).Columns.Remove("STATUS_DESCRIPTION")
                    resultsDataSet.Tables(0).Columns.Remove("CORP_TYPE")
                    resultsDataSet.Tables(0).Columns.Remove("Name")
                    DisplayResults.AutoGenerateSelectButton = False
                    DisplayResults.DataBind()

as you can see, I have a Select Case section where I elected to remove some columns before calling DataBind(). In addition, I turn off the Select Button prior to rendering the datagrid.

It's a flexible option: datasets are almost little DBs themselves and you can manipulate them in-memory, which is nice.

0

Hello All,

Well I did try your suggestions howerver nothing worked. I think next time I will manually create the Table and writ ethe code rathe rthan use the Gridview for this tyoe of situation. With that said here is what i did.

1. Convert the column to a template
2. The columns that I want to hide - site the width to 0
3. In the ItemTemplate just remove the text so that the column title is is blank
4. On the ASP: Code set GridLines = None
5. In the edit template Put the text/check box you want to use

Doing the above steps allowed me to hide the columns in "Normal mode" and have them show in edit mode.

Thanks guys for all the help,
Tommy

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.