473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to insert value in dropdownlist in the footer row of gridview?

2 New Member
I have Gridview with Template Field.And I Put Dropdownlist at footer row of gridview. but when i insert the value from a database table in dropdownlist , than it generate error.
for filling value ,

i declare variable like in databound event of gridview.
for example:

dim varclass as new dropdownlist
varclass=Gridvi ew1.footerRow.f indcontrol("ddl Class")

it generate error that: Object reference not set to an instance of an object.
So any one have Answer??
Jan 12 '10 #1
1 4196
Frinavale
9,735 Recognized Expert Moderator Expert
You should be checking to make sure that the row being bound is the Footer and not a Header or Data row. If you try to access a variable in the footer row when it isn't the footer row that is being bound then you'll have a problem.

For example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
  2.  
  3.   Select Case e.Row.RowType
  4.     Case DataControlRowType.Header
  5.       'In this case the header row is being bound 
  6.       'All controls in the header row are accessible
  7.     Case DataControlRowType.DataRow
  8.       'In this case a Data Row is being bound
  9.       'All controls in the data row are accessible
  10.     Case DataControlRowType.Footer
  11.       'In this case the footer row is being bound
  12.       'All controls in the footer row are now accessible
  13.     Case DataControlRowType.Pager
  14.       'In this case the pager row is being bound
  15.       'All controls in the pager row are accessible
  16. '....
  17.   End Select
  18.  
  19. End Sub
The controls available to you all depends on which row is currently being bound. If the row being bound is a data row, then obviously you wont find controls that are in the footer row.

When you use the findControl method you should always make sure that the control was found before you try to use it (check to make sure that the control IsNot Nothing before you try to use it)

-Frinny
Jan 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4902
by: Hennie | last post by:
I have a textbox in the Footer of a Gridview. When I run an insert command I get the following error: " Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an...
1
1910
by: Hennie | last post by:
Hi Is it possible to insert records using the Footer row in a Gridview? I can do it with a datagrid in VS2003, but the same code in VS2005 give me an error: The code is: Dim strOperatorID As String = CType(GVProgram.FindControl("ddlOperatorID"), DropDownList).SelectedValue Error: Exception Details: System.NullReferenceException: Object reference not set
6
14464
by: AG | last post by:
ASP.NET 2.0 aspx page with a FormView bound to an ObjectDataSource to view, add and edit records. Can anyone point me to a sample of how to retain the user entered control values when an insert fails? In other words, when inserting a new record, user enters data in the controls, but the insert fails. When the page posts back all the controls are empty or at their default values. I would like to retain the user enter values so they can...
1
6136
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
1
1537
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is not empty. when i click on the insert Link the data should be displayed in the gridView (Which is below the formview), But when i click on the Insert link the data is displayed in the gridView, But the DropdownList is empty. Here is the...
0
1220
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is not empty. when i click on the insert Link the data should be displayed in the gridView (Which is below the formview), But when i click on the Insert link the data is displayed in the gridView, But the DropdownList is empty.
2
10852
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button, for example, in the GridView footer. When this button is clicked it should put the GridView in Insert Mode and the EditTemplate should be showed, maybe (?), in the last GridView
0
4066
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the following: 1) gets query string from url and filters records (works great) via a Details View 2) shows notes that have been added to the record shown in the details view using a grid view, and it filters the data by looking at the ID that is selected in...
0
3028
by: dcollier9 | last post by:
Hi ! I need to embed a text box in a footer of a GridView's boundfield column to get data prior to a row insert. The textbox is usable and showing up in the web page source using View
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.