Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > asp:DropDownList problem

Reply
Thread Tools

asp:DropDownList problem

 
 
Maziar Aflatoun
Guest
Posts: n/a
 
      11-14-2003
Hi everyone,

I am trying to select an item in my DropDownList (Everything on 1 .aspx
page) and it gives me the following error message. Has anyone encountered
this problem before? or any idea how I can resolve it? (In this case I want
to select the Canada from the country list)

SqlDataAdapter daCountry = new SqlDataAdapter("SELECT * FROM Country ORDER
BY Value", conn);
DataSet dsCountry = new DataSet();
daCountry.Fill(dsCountry, "Country");
Country.DataSource = dsCountry.Tables["Country"];
Country.DataTextField = "Value";
Country.DataValueField = "Key";
//Country.ClearSelection();
Country.Items.FindByText("Canada").Selected = true;
Country.DataBind();


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 instance of an object.

Source Error:


Line 27: Country.DataValueField = "Key";
Line 28: //Country.ClearSelection();
Line 29: Country.Items.FindByText("Canada").Selected = true;
Line 30:
Line 31: Country.DataBind();




Thank you
Maziar A.


 
Reply With Quote
 
 
 
 
Bill Priess
Guest
Posts: n/a
 
      11-14-2003
Try this:
Country.SelectedIndex =
Country.Items.IndexOf(Country.Items.FindByText("Ca nada"));

HTH,
Bill P.

"Maziar Aflatoun" <(E-Mail Removed)> wrote in message
news:wg7tb.67315$(E-Mail Removed) e.rogers.com...
> Hi everyone,
>
> I am trying to select an item in my DropDownList (Everything on 1 .aspx
> page) and it gives me the following error message. Has anyone encountered
> this problem before? or any idea how I can resolve it? (In this case I

want
> to select the Canada from the country list)
>
> SqlDataAdapter daCountry = new SqlDataAdapter("SELECT * FROM Country ORDER
> BY Value", conn);
> DataSet dsCountry = new DataSet();
> daCountry.Fill(dsCountry, "Country");
> Country.DataSource = dsCountry.Tables["Country"];
> Country.DataTextField = "Value";
> Country.DataValueField = "Key";
> //Country.ClearSelection();
> Country.Items.FindByText("Canada").Selected = true;
> Country.DataBind();
>
>
> 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 instance of an object.
>
> Source Error:
>
>
> Line 27: Country.DataValueField = "Key";
> Line 28: //Country.ClearSelection();
> Line 29: Country.Items.FindByText("Canada").Selected = true;
> Line 30:
> Line 31: Country.DataBind();
>
>
>
>
> Thank you
> Maziar A.
>
>



 
Reply With Quote
 
 
 
 
Maziar Aflatoun
Guest
Posts: n/a
 
      11-14-2003
Thanks worked

Maz.

"Bill Priess" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Try this:
> Country.SelectedIndex =
> Country.Items.IndexOf(Country.Items.FindByText("Ca nada"));
>
> HTH,
> Bill P.
>
> "Maziar Aflatoun" <(E-Mail Removed)> wrote in message
> news:wg7tb.67315$(E-Mail Removed) e.rogers.com...
> > Hi everyone,
> >
> > I am trying to select an item in my DropDownList (Everything on 1 .aspx
> > page) and it gives me the following error message. Has anyone

encountered
> > this problem before? or any idea how I can resolve it? (In this case I

> want
> > to select the Canada from the country list)
> >
> > SqlDataAdapter daCountry = new SqlDataAdapter("SELECT * FROM Country

ORDER
> > BY Value", conn);
> > DataSet dsCountry = new DataSet();
> > daCountry.Fill(dsCountry, "Country");
> > Country.DataSource = dsCountry.Tables["Country"];
> > Country.DataTextField = "Value";
> > Country.DataValueField = "Key";
> > //Country.ClearSelection();
> > Country.Items.FindByText("Canada").Selected = true;
> > Country.DataBind();
> >
> >
> > 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 instance of an object.
> >
> > Source Error:
> >
> >
> > Line 27: Country.DataValueField = "Key";
> > Line 28: //Country.ClearSelection();
> > Line 29: Country.Items.FindByText("Canada").Selected = true;
> > Line 30:
> > Line 31: Country.DataBind();
> >
> >
> >
> >
> > Thank you
> > Maziar A.
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments