Showing/Hiding Rows in a Gridview control in Render Event


I'm using a Gridview control and need to be able to hide or show a row in a Gridview control in the Render event of a Content page.   Is there an easy way to do this?

There is a <asp:LinkButton> on the Master Page that indicates either to Show or Hide error messages.

 When I used the following code, it hides all rows.

                foreach (GridViewRow row in inGridView.Rows)
                    DataBoundLiteralControl myDealErrorBit = (DataBoundLiteralControl)row.Cells[14].Controls[0];
                    currentValue = myDealErrorBit.Text;
                    //User clicked Show Messages on the Master Page
                    if (Master.ShowErrorMessages == true)
                        if (Convert.ToBoolean(currentValue) == true)
                            row.ForeColor = System.Drawing.Color.Red;
                        row.Visible = false;


11/20/2007 4:17:15 PM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 54

Try it in PreRender.  Render is too late.


I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
11/20/2007 10:08:51 PM

The same result occurs when I move the code to the PreRender event.  All rows are hidden.

11/21/2007 1:33:54 PM

It seems to me that since the control hasn't been drawn yet, you can't interrogate it directly.  Everything is getting hidden because the true condition doesn't apply.  Try stepping through the code and see if you ever get to the rowforecolor section.  Of course, I'm a little surprised you don't get a null condition error if that were the case, so it is entirely possible I'm wrong.

I have a couple of ideas for you.

1) Interrogate the database or the object that the GV is bound to instead of the control value.

2) Filter the data before you bind it instead of setting the visibility.

3) If the condition you are selecting on isn't in the database or object, create a session variable to hold an array that gets built as the user makes selections that will take effect on the postback and interrogate that instead of the row object.

I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
11/21/2007 1:56:05 PM

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

Gridview row click event fires, when clicking on controls within row.
I have a gridview control and I have added  a row click event which causes a post back. e.Row.Attributes.Add("onClick", this.Page.ClientScript.GetPostBackEventReference(this, "Select$" + e.Row.RowIndex.ToString()));  When the user clicks the row, i bind some data to a checkbox list, showing a uers a list of options they have chosen. All good so far. I also have a edit button for each row. When the row is in edit mode i display a checkbox and textbox. Problem is when i click on the textbox or the checkbox, it causes the row click event to fire. Any ida...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,,MC...

Dyamically creating a control vs Show/Hide controls
Hi , I am trying to develop a quiz application that displays one question per page to a user. The question type could be radio button list style , check box list  type, True/False type or Fill-in the blanks type. I can think of two ways to render the questions on the Questions Web page 1) Dynamically create the UI control ( Radio Button or checkbox etc) based on the Question type and inject into the Questions Web page 2) Have all the UI control types layed out statically on the web page and show only the approriate UI control type based on the Question type, while hiding the o...

Updating and binding control to other controls within the same row of a GridView
HiIn the EditTemplate of my GridView I show 2 DropDownLists. When the user selects the first dropdownlist, I need it to update the contents of the second dropdownlist. I have my Subs that do this fine when not inside the GridView, but what is the correct way to do it whilst they are in the GridView?This is my current attempt that returns the error 'Object reference not set to an instance of an object'. I presume its related to correctly targeting the DropDownList in question? This is my GridView:<asp:GridView ID="GridView1" runat="server"  &...

How do you assign control events to control created in a gridview ItemTemplate?
Say that you have: <asp:gridView id="gvTest" runat="server"> <columns> <itemTemplate> <asp:button id="btn_<%# Eval("id")%>" runat="server" /> </itemTemplate> </columns> </asp:gridView> What do I need to do in the code behind to associate each one of these buttons to be handled by Sub "btn_Click()"?   J Hello, I'm not sure if this answers your question. You need to hook up the CommandName to your button and GridView's OnItemCommand handler. From your onItemCommand function, handles your click appropriately.Liming XuJumptree ASP....

Button on User Control to show/hide controls on Page
Hi, I created a User Control in my ASP.NET application that acts as a filter for a gridview.  Everything works fine with that.  I tried adding a button into that User Control to "Add a New Record".  The code for that button will vary from page to page.  I am having a hard time figuring out how to program that button on each page to access the controls of the page.  I am using Interfaces and Implements to access the function/sub. I created the follwing Interface in one of my Classes.  Then I create the Event Handler for the button inside the user cont...

Custom User controls not hiding or showing in Acordian control.
I have created several Web User controls and would like to put them in seperate Acordian panes.  The first control I used absolute positioning when creating it and it will not hide at all. I assumed that the absolute positioning was messing things up. So I rebuilt it without absolute positioning and now it does not show up at all.  I have tested puting Standard .Net controls like texboxes in the panes so I know the panes work ok. The control is in the second pane and is called cti_AgentImage. The Acordian code is: <body><form id="form1" runat="server"><div><...

Handling control events while in edit mode for a gridview control
I have a dropdownlist and checkbox in a single column of a gridview. While the row is in edit mode, I want to set the visibility of the checkbox based on the value selected in the dropdown list. I can do this easily enough  when the row is first put into edit mode, but how do I access the dropdown list's change event when the row is already sitting there in edit mode? Thanks for any help you can provide.   Penny Penny, Just create a SelectedIndexChanged event like below. Create a row object for the currently edited row, find the checkbox you want to control, then set the Visib...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

How to show footer row in GridView control?
 I have a GridView control that I modified the footer so I can insert new record. The problem is if there isn't any existing record in the database, the GridView control just won't show anything even the footer for adding new record. Is there a way to modify the GridView control so regardless if the SqlDataSource control that I used to populate the GridView control has 0 affected rows or not, the footer will always show up so that I can add new record in? Here you go: Rega...

Showing/hiding control in ItemTemplate in gridview
I want to either show or hide a button in a templatefield/itemtemplate based on the text in the 2nd column of the gridview.  I haven't done anything like this before so not sure how to accomplish.  If the text in the 2nd column is "POSTED" I want to show the button.  Otherwise I want it hidden.   I was looking at RowDataBound event of gridview, with something like this:Protected Sub grdBidResponse_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdBidResponse.RowDataBound       ...

Gridview control embedded in another gridview control
I am writing an ambulance crew scheduling application on the web and I need some help completing the last part.  I have an access database that has three tables: user table, shift table (describing the shifts available), and a schedule table (that stores shift by shift_id and user by user_id).  I have a gridview control that will display the available shifts but I cannot get the embedded gridview control that will display the user that is signed up for each shift to display because I cannot figure out how to use the OnRowDataBound method.  I need a simple VB example of how to...

Web resources about - Showing/Hiding Rows in a Gridview control in Render Event -

Resources last updated: 11/26/2015 11:57:51 PM