Detecting Footer Row vs Data row in a gridview


I am trying to run validation controls using page pre-render in vb for a gridview where I have the insert in the footer of the gridview and updates in the individual rows. The Prerender will highlight the controls which have failed the validation.

My problem is that when the Page prerender fires, I cannot figure out how to get the controls depending on whether it is an insert from the footer, or an update from a regular row in the Gridview.

The insert from the footer works well, but the update from a Gridview row does not.

Also I have got a formview in the gridviews empty template which also works well.

Here is my code:

1    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
2            If Page.IsPostBack Then
3                For Each valControl As BaseValidator In Page.Validators
4                    If GridView1.Rows.Count > 0 Then
6                        Dim badControl As WebControl = GridView1.FooterRow.FindControl(valControl.ControlToValidate)
7                        If Not valControl.IsValid Then
9                            badControl.BackColor = Drawing.Color.Yellow
11                       Else
13                           badControl.BackColor = Drawing.Color.White
15                       End If
19                   Else
20                       Dim EmptyInsert As FormView = CType(GridView1.Controls(0).Controls(0).FindControl("Formview1"), FormView)
21                       Dim badControl As WebControl = EmptyInsert.FindControl(valControl.ControlToValidate)
23                       If Not valControl.IsValid Then
25                           badControl.BackColor = Drawing.Color.Yellow
27                       Else
29                           badControl.BackColor = Drawing.Color.White
31                       End If
33                   End If
34               Next
35           End If
36       End Sub

 Any help would be appreciated!Smile

6/20/2008 9:53:22 AM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 51

try this..

protected void Page_Load(object sender, EventArgs e)


GridView gv = new GridView();gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound);


void gv_RowDataBound(object sender, GridViewRowEventArgs e)


if (e.Row.RowType == DataControlRowType.Footer || e.Row.RowType == DataControlRowType.Header)





"Mark as answered if you feel this helps you"
"Curiosity is Bliss"

Ravi Kant Srivastava
(Sr. Consultant I)
6/20/2008 10:49:43 AM

I'm not sure if I follow you exactly but, could you put some processing in your GridView RowDataBound event and check for the footer there?


Private Sub GridView1_RowDataBound(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles GridView1.RowDataBound
 If e.Row.RowType = DataControlRowType.Footer Then
   ' Put Processing Here
 End If
End Sub
6/20/2008 10:52:28 AM

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 ...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

Display the footer row of the gridview control even there is no data.
Hi, I want to display the footer row of the gridview control eventhough there is no data. Is this possible. Second approach: I putted some text boxes and lables and and "Add" button in gridviews Emplytemplete mode. I want the user to enter some values in the textboxes and when he hits the "add" button it should add a row to database and rebind the gridview. How can I make it work?  Thanks in advance. SyedSyed Ali Shah______________________________________________Attention: Don't Forget to mark as "Answer" If I helped you in solving your problem. H...

How to automatically copy the value of a gridview row to a field in the gridview footer row
Hello,  How to automatically copy the existing value displayed in a gridview row to a field in the gridview footer row.  Both fields are of the same type.  The gridbew row is used to modify information and the footer row is used to add new information to the db. Gridview1.FindControl("WorkOrderID) GridView1.FooterRow.FindControl("NewWorkOrderID")   Thank you,ptown check this link..,Punithkumar 1 - turn column into template 2 - Add a label to footer template 3 - Say yo...

Populate row by row data in gridview
Hi , How to populate the data row by row in grid view. For example: I wirte this code in .aspx page <asp:TemplateField HeaderText="COC Date of Calibration">                <EditItemTemplate>                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# COC_Date("strDate") %>'></asp:TextBox>       &nbs...

Accessing GridView Data Row By Row
guys i have just started with i have a basic doubt, i have created a SQL datasource and a gridview associated with it now what i need to do is get all the data from my database n modify it further, for this i need to access each row of the gridview any ideas on how to do so? foreach(GridViewRow row in GridViewName.Rows) { you can interate like this..  }Better Post your code before asking some thing, some one. So that person helping u will understand u r problem ClearlyYahoo IM : dotnetrulerI am trying to keep Frequently Asked Questions in my blog  When u enable show...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

copy data from excel row to gridview row
Hi All, I need to copy data from excel to gridview. I have to select a row and press Ctrl+C to copy from excel, then I have to paste it in Gridview. Thanks in advance. I dont think you can Copy and Paste data from Excel to Gridview.But you can export data from Excel to GridView control, please check the below articles. a Reply as 'Answered', not only GAIN us some POINTS, but it also HELP others to find RIGHT solution....

How To: Reference controls in footer row from an item row
I'm familiar with using the e.Item.FindControl command when manipulating controls from an item row or footer row when you are actually in (editing) that row. I'm also familiar with determining what "Type" of row I'm in. What I'm having troubles with is referencing a control in the footer row of a datagrid while I'm actually in (editing) an item row. Can this be done? Thanks Mike...

Gridview row editing fields based on row data
Is there a way to change row editable fields in a databound gridview based on the rows data. For example letting a user edit all his and his fellows fields but preventing him from changing specific fields in his boss data on the same gridview? Help will be great fully appreciated. Thanks If I understand what you are saying is that you want to only allow a user to Edit certain rows within the GridView. If so, yes, you certainly can do this. What I would do is hide/display the Edit Button for a row based on the user's role or permissions. This can easily be done via the RowDataBound e...

Multiple grid rows per Data row in GridView
I have a dataset that is binded to a gridview. The dataset has 5 fields and a description. I want to display 1 row for the 5 short fields and 1 row underneath it for the description. (per record)   For example: ID Name  Surname Field3 Field 4 1   John     Smith      blah    blah     This is the long description for  John Smith spanning 5 cells 2   Peter    Parker     blah    blah     This is t... problem: i can not view image data for the rest of my table rows except the image for the first row but i can read all the other non image fields for all rows.
Hi i have a table with the following fields imgdata........image imgtitle.........varchar(max) imgType........varchar(max) imgLength.....bigint i have no problem with uploading the image but viewing the uploaded image(s) in a gridview has caused me great pain. The probelm is i have two pages. page1 grabs the image to display and page2 has a gridview that displays the grabed image. I wanted to have an sql statement like SELECT * FROM mytable WHERE incident_id=someValue. IF i have 5 records in this table and i view page2 ...

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

add data from multiple rows in table to one row in gridview
 heya is there any way of adding data from multiple rows in table to one row in gridview. eg. ipc                 column 1 ,            2 ,                       3,                 4  1,    11111                 33                  &nbs...

Web resources about - Detecting Footer Row vs Data row in a gridview -

Methods of detecting exoplanets - Wikipedia, the free encyclopedia
Any planet is an extremely faint light source compared to its parent star . In addition to the intrinsic difficulty of detecting such a faint ...

Detecting unauthorized cross-app resource access on OS X
Last week, Luyi Xing, a Ph.D. student from Indiana University Bloomington and his colleagues released a research paper on several vulnerabilities ...

Neuroethology of Toads (Part 2 of 3; English): Feature Detecting Nerve Cells in the Brain - YouTube
Movie with the title "Image Processing in the Visual System of the Common Toad - Behavior, Brain Function, Artificial Neuronal Net" (IWF No. ...

Detecting and treating arthritis in dogs
Arthritis is very common in older dogs but there are ways to keep them comfortable and happy.

Detecting APT Activity with Network Traffic Analysis
Computerworld Australia is the leading source of technology news, analysis and tools for IT decision makers, managers and professionals.

Malware-detecting 'sandboxing' technology no silver bullet - Palo Alto, mcafee, trend micro, security ...
The security technology called "sandboxing" aims at detecting malware code by subjecting it to run in a computer-based system of one type of ...

Researchers close to developing a blood test for detecting Alzheimer’s
A team of scientists say they are getting closer to detecting Alzheimer’s antibodies at the preclinical stage, giving patients an opportunity ...

Threat-detecting surveillence cameras among first start-up projects to benefit from local Microsoft Innovation ...
South Australia's start-up support initiatives give funding to system that foils armed hold-ups by locking the shop doors to suspicious people. ...

Detecting APT Activity with Network Traffic Analysis
Defining Technology for Australia's IT Leaders.

Shrimp's eyes inspire new cancer-detecting camera
Shrimps' eyes have been revealed as the latest weapon against cancer, with their unique vision set to be adapted to diagnostic cameras.

resources last updated: 11/20/2015 12:45:00 PM