Topic: asp.net homework help

I'm working on a homework assignment for one of my classes and having a problem getting my drop down list working they way I need it to.

So what I need to do is choose one thing on a list and when the user clicks submit, a panel will appear with the corresponding text and images. 

I made it work with radio buttons, but when I went back to check the assignment requirements, the instructor was a drop down list sad.

This is the code for the radio button:

if (rdoCapricorn.Checked)
 {
            pnlRead.Visible = true;
            pnlHoroscopes.Visible = true;

            lblSign.Text = "Capricorn";
            imgHoroscope.ImageUrl = "~/signs/capricorn.png";
            lblHoroscope.Text = "blah blah blah";
}

So the problem I am having is doing the same thing with a drop down list.

I tried using the following lines for the if statement:

if (ddlZodiac.SelectedItem = "Capricorn")
if (ddlZodiac.SelectedIndex = 0)
if (ddlZodiac.DataValueField = "Capricorn")
if (ddlZodiac.DataTextFormatString = "Capricorn")

and I getting an error "cannot implicitly convert type string (or int) to bool".   I even tried the .ToString at the end of SelectedItem but I get another error which says, "cannot assign to ToString because it is a 'method group'".  I don't fully understand the errors which I think is why I'm having a problem.

There has to be simple solution to this that I am completely missing.  I don't think our instructor covered.  I'm not sure if this makes a difference, but the drop down list has an SqlDataSource called "theZodiac".


below is the code to display the drop down list and code for the database:

            <asp:DropDownList ID="ddlZodiac" runat="server" 
                DataSourceID="theZodiac" 
                DataTextField="Sign" DataValueField="Sign">
            </asp:DropDownList>


            <asp:SqlDataSource ID="theZodiac" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT [Sign] FROM [zodiacSign]">
            </asp:SqlDataSource>

I'm sorry if this seems like a lot.  I'm very new to ASP.Net, so I want to know how to make it work and why the methods I was trying above did not so I know for future reference.

Thanks in advance to anyone who replies! wink

Re: asp.net homework help

It's been a looong time since I did any .net, but if I recall correctly, the correct syntax is:

(c#)

if(ddlZodiac.SelectedItem.Value == "Capricorn")

(vb)

if(ddlZodiac.SelectedItem.Value = "Capricorn")

Let me know if that works / doesn't work. smile

Re: asp.net homework help

THANK YOU SO MUCH!  It worked!  I completely forgot about that syntax.  This way easier for me than using a database.

I managed to make it work with a database after about 3 hours of frustration.  The only thing I was unable to do in using a database was getting an image to appear in a Detail View Grid. 

I tried using varchar(MAX) and used <img>, but it just displays the code in the grid output:

http://i247.photobucket.com/albums/gg135/krazigoddezz/zodiacTable.jpg

At first, I tried using "Image" for the type, but it wouldn't work when I used the url path or using <img>.  What am I doing wrong?

Once again, thanks monkeysaurus and thank you in advance to anyone who can answer this question.

Last edited by krazigoddezz (2009-04-07 16:59:07)

Re: asp.net homework help

Well done on getting that working. Looks like you're nearly there!

Err, to repeat, my asp.net is very rusty, but I think selecting Image as the field type and then entering the URL of the image should work. Have you double and triple checked your image paths?

I would suggest troubleshooting by entering the URL of an image you know is correct, and is online somewhere. For example:
http://newsimg.bbc.co.uk/media/images/4 … _ap226.jpg

If the image appears properly, then it's probably a problem with your paths.

Sorry I can't help further - perhaps someone else can help out?

Re: asp.net homework help

I just came across a site named tutorsonnet.com, which provides online homework help for all the major subjects. I just wanted to share this information. Hope this will help you.

homework help