Ask a Question related to ASP.NET General, Design and Development.
-
huobazi #1
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>
huobazi Guest
-
Dropdownlist "Select Value Equal To" Gives an Error
In DW MX 2004 (C#), when I set the "select value equal to" for a dropdownlist item, I get the following .NET error once I try to view the webpage: ... -
"Unable to continue because of a hardware or system error"
I suddenly started receiving this message when opening Elements 2. The message continues - "Sorry, but this error is unrecoverable." I've uninstalled... -
Lsass.exe System error "object name not found". System keeps rebooting
When trying to install the drivers for the PCI modem in my laptop, prompted for the driver CD. Installed the driver without any errors but asked... -
"cannot find server or DNS error" after installing 1394 card in XP system
After intalling a 1394 firewire card in my xp machine, IE can no longer connect to the internet. Even after I remove the card and uninstall it... -
Error: System.Windows.Forms.SendKeys.SendWait("%{T}")
I am trying to send the key Alt + T using the send wait method: syntax: System.Windows.Forms.SendKeys.SendWait("%{T}") But I am receiving the...



Reply With Quote

