473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Still can't see why I'm getting this error!

I keep getting the following error on a dropdownlist control I have added to a datagrid! I have given the control the correct id and don't get any errors when conpiling the code but as soon as I try to access the page I receive the error show below!

Can someone please tell me why and how I might fix it!

Thanks!

ERROR: Object reference not set to an instance of an object.
...::INLINE CODE
<asp:datagrid id="DGPages" runat="server" OnDeleteCommand="DGPages_Delete" OnCancelCommand="DGPages_Cancel"
OnUpdateCommand="DGPages_Update" OnEditCommand="DGPages_Edit" DataKeyField="pageID" AutoGenerateColumns="False" Width="90%" CellPadding="4" EditItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Black" HeaderStyle-ForeColor="White" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ShowFooter="True">
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<%# Container.DataItem("pageID") %>
</ItemTemplate>
<EditItemTemplate>
<%# Container.DataItem("pageID") %>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<%# Container.DataItem("description") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="description" Columns="5" Text='<%# Container.DataItem("description") %>' Runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="add_Description" Columns="5" Runat="Server" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate>
<%# Container.DataItem("header") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="title" Columns="5" Text='<%# Container.DataItem("header") %>' Runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="add_title" Columns="5" Runat="Server" />
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Office">
<ItemTemplate>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="office" Columns="5" Text='<%# Container.DataItem("offName") %>' Runat="server" />
</EditItemTemplate>
<FooterTemplate>
<!-- Pull Office Names from Database -->
<asp:DropDownList id="add_Office" runat="server"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" HeaderText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="Delete">
<FooterTemplate>
<asp:Button CommandName="Insert" Text="Add" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Button CommandName="Delete" Text="Delete" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

...:: CODE BEHIND
Sub PopulateDropdown()
' Only pull data from db on first page call.
If Not Page.IsPostBack Then
' Create connection
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("SelectOffice", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

' Get a new datareader from our command
Dim myReader As SqlDataReader = cmd.ExecuteReader()
add_Office.DataSource = myReader ' *** ERROR HERE
add_Office.DataValueField = "officeID"
add_Office.DataTextField = "offName"
add_Office.DataBind()

myReader.Close()

Myconn.Close()
End If
End Sub
Nov 18 '05 #1
0 1208

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lkrubner | last post by:
I was trying to set a cookie before I called session_start() and it was giving me an error. But isn't sessions really just a cookie? Why would it matter if I sent a cookie before session_start? Can...
2
by: Roy Gourgi | last post by:
Hi, Here is my code. I get the error message now that it expects a ")". I have tried a few different things, but to no avail. What am I doing wrong???? I can't believe that it is so difficult to...
6
by: Martin | last post by:
Hi, I had a page the other day for which the compiler just wouldn't recognize the fact that I had enabled session state in every possible way. I ended up moving the code that dealt with the...
9
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
29
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's...
2
by: soma.gunasekaran | last post by:
Hi All , I've stored the Image file..... But i want to retriving the Image files from MSACCSS 2003 (JPEG,bmp,Gif and etc....) So Pls help me........ help me............... Thanking you,...
10
by: Mike | last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an...
3
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am getting the following error :- 1>------ Build started: Project: Polygon Drawer, Configuration: Debug Win32 ------ 1>Compiling... 1>Dialog.cpp 1>g:\my subjects\3rd semester\project...
2
by: darrel | last post by:
Quick background: Our department reveived new PCs a few weeks ago. Alas, due to new security policies, we weren't immediately set up as admins of our own machines, so most of us developers had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.