473,412 Members | 1,973 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,412 software developers and data experts.

Help Me~~My DropDownList Can not get the"BigClassList.SelectedItem.Text" there is an error: System.NullReferenceException


I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)"
but when i want to get the BigClassList.SelectedItem.Text and BigClassList.SelectedItem.Value in a button onclick method,btnSmallClassEdit_Click(....),there post an error " System.NullReferenceException: 佫¶ÔÏóÒýÓÃÉèÖõ½¶ÔÏóµÄʵÀý¡£",

I Don't know the wrong is where in my code, pls help me thanks!!!
I guess the BigClassList.SelectedItem.Text and BigClassList.SelectedItem.Value may be null
///////a part of my codes here//////////////////////////////////////////////////////
///My connection defined in the parent page which is inherits from the class "Page";
// And i make sure the type, and ID matches to the HTML, and HTML declaration of BigClassList has a
// runat=server attribute and in a "<form runat=server>" tags .
////////////////////////////////////////////////////////////////////////////////////
public void Page_Load(Object sender,EventArgs e)

{

if(!IsPostBack)

{
BigClassDropDownListInit();
}
}
public void BigClassDropDownListInit()
{
InitList(BigClassList,"select ID,BigClassName from RootClass order by BigClassName","BigClassName","ID");
}
public void InitList(DropDownList list,string strsql,string TextField,string ValueField)
{
Conn.Open();
Cmd =new OleDbCommand(strsql,Conn);
OleDbDataReader Rd = Cmd.ExecuteReader();
list.DataSource=Rd;
list.DataTextField=TextField;
list.DataValueField=ValueField;
list.DataBind();
Rd.Close();
Conn.Close();
}
public void btnSmallClassAdd_Click(Object sender,EventArgs e)
{
Conn.Open();
OleDbCommand commTest=new OleDbCommand("select * from Type where TypeName='"+txtSmallClassAdd.Text+"'",Conn);
int i=commTest.ExecuteNonQuery();
Conn.Close();
if(i>0)
Response.Write("<script>alert('ÒÑÓÐͬÃû·ÖÀà´æÔÚ!') ;</script>");
else
{
string strInsert="insert into Type(TypeName,BigClassName,BigID) Values ('"+txtSmallClassAdd.Text+"','"+BigClassList.Selec tedItem.Text+"','"+BigClassList.SelectedItem.Value +"')";

Conn.Open();
OleDbCommand commAdd=new OleDbCommand(strInsert,Conn);
commAdd.ExecuteNonQuery();
Conn.Close();
Response.Write("<script>alert('¶þ¼¶·ÖÀàÌí¼Ó³É¹¦!') ;</script>");
}
BigClassDropDownListInit();
SmallClassDropDownListInit();
}
////////////////about the ascx fiels code here//
<td width="80%" valign="middle" bgcolor="#FFFFFF"><font color="#000000">
¡¡ÔÚ:</font> <asp:dropdownlist ID="BigClassList" Width="100" runat="server" ></asp:dropdownlist> <font color="#000000">ÖÐÔö¼Ó¶þ¼¶À¸Ä¿ </font> <asp:textbox ID="txtSmallClassAdd" Width="100" runat="server" ></asp:textbox> <asp:button ID="btnSmallClassAdd" OnClick="btnSmallClassAdd_Click" Text="Ìí¼Ó" runat="server" ></asp:button> </td>
Nov 17 '05 #1
0 1957

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

Similar topics

2
by: Shannon | last post by:
I am having a very strange issue with my asp.net application. I have created a datagrid which dynamically gets populated from a person choosing a value from a dropdown list and entering a quantity...
0
by: noe | last post by:
I have done a DLL in unmanaged code C++ and in that dll I have defined a function that use memcpy.This dll run ok.I use that dll in a aplication in C# managed code in Visual Studio .NET. I import...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
5
by: Patrick.O.Ige | last post by:
What could cause the error:- System.NullReferenceException: Object reference not set to an instance of an object. Any ideas?
4
by: Brian | last post by:
i have a radiobuttonlist. I want to check to see if a button has been selected then get the value.. This was my code; ---------------------------------------------------------------- Dim...
7
by: VB Programmer | last post by:
(Using Whidbey, but I don't think it matters.) I keep getting this error: System.NullReferenceException: Object reference not set to an instance of an object. Here is the line it's happening...
5
by: zvikorn | last post by:
Hi, I'm trying to call a function written in a dll file, from ASP.NET 1.1 web application. Part of code in global.asax: <%@ Import namespace="WPPSYSTEMDLLLib" %> Sub Application_OnStart()
4
by: Cirene | last post by:
Using asp.net membership. My login.aspx page goes to the loginredirect.aspx page after the user logs in. For some reason "Membership.GetUser.ProviderUserKey.ToString" gives me this error:...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.