How to Hide A GridView Column in a Visual Web Developer project
-
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 :confused: Thanks! Tommy
-
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 :confused: Thanks! Tommy
if your column is 11 in grid view than u need to hide 10 one because in grid column start from 0 as base index so you code may be
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(10).Visible = TrueElseIf e.Row.RowState = DataControlRowState.Normal Then
GridView1.Columns(10).Visible = FalseEnd If
End SubFor more help : pranayamr@gmail.com
-
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 :confused: Thanks! Tommy
Check this blog post - Hide GridView columns in normal mode, and show more columns in edit mode[^] HTH!
-
if your column is 11 in grid view than u need to hide 10 one because in grid column start from 0 as base index so you code may be
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(10).Visible = TrueElseIf e.Row.RowState = DataControlRowState.Normal Then
GridView1.Columns(10).Visible = FalseEnd If
End SubFor more help : pranayamr@gmail.com
Pranay, I did take that in to account to be sure I did change to 10 see the result. Its was the same but just on the 10th column. I still get the StackOverflowExceptionwasunhandled As if its looping but I don't understand why. Thanks,
-
Check this blog post - Hide GridView columns in normal mode, and show more columns in edit mode[^] HTH!
Dinesh, I did find this however I am not too familiar with c# If you could help translate this toe VB.net that would be fantastic. Thanks, Tommy :laugh:
-
Dinesh, I did find this however I am not too familiar with c# If you could help translate this toe VB.net that would be fantastic. Thanks, Tommy :laugh:
I've tried to translate the coding from C# to VB.NET. I think this is the equivalent -
Protected Sub GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
If (GridView1.EditIndex < 0) Then
Exit sub
End IfIf ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)) Then e.Row.Cells(2).Visible = False e.Row.Cells(3).Visible = False End If
End Sub
NOTE: I've not worked in VB.NET for sometime so go easy on me if it doesn't work :-\ HTH!!
-
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 :confused: Thanks! Tommy
Hi, grafiksinc U just take the parameter as 10 in the columns of grid view and check the result. Thanks.
-
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 :confused: Thanks! Tommy
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 :laugh: