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

Discussion in 'ASP .Net' started by huobazi, Jul 1, 2003.

  1. huobazi

    huobazi Guest

    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.SelectedItem.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, Jul 1, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sfunds sfunds
    Replies:
    9
    Views:
    8,665
  2. =?Utf-8?B?RGF2aWRT?=
    Replies:
    4
    Views:
    1,721
    =?Utf-8?B?RGF2aWRT?=
    Oct 8, 2004
  3. Jarod
    Replies:
    1
    Views:
    2,375
    Matt Dinovo
    Jan 26, 2006
  4. Replies:
    4
    Views:
    798
  5. Rymfax
    Replies:
    2
    Views:
    816
    JussiJ
    May 31, 2007
Loading...

Share This Page