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 :-/

Recommended Answers

All 3 Replies

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.

Don't use AutoGeneratedColumns. Configure GridColumns manually.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.