Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 19, 2008 2:34 PM
I am using the AJAX Cascading Style Menu code that was given in this example: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx (If you click on the "watch video" link, there is a link to download the code also). I had to change the C# code a little bit because I have my dropdown menus within a form, so I changed the C# code to find the controls in the form. The problem I am having is that when I try to run this code, I get the error message: CS1502: The best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments. The error calls out this line of code: if (string.IsNullOrEmpty(make))
What is wrong with that code?
Thanks,
Mary
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Collections.Specialized;
using AjaxControlToolkit;
public partial class Nanny_NannyMembers_temp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
// Get selected values
DropDownList make = (DropDownList)FormView1.FindControl("DropDownList1");
DropDownList model = (DropDownList)FormView1.FindControl("DropDownList2");
DropDownList color = (DropDownList)FormView1.FindControl("DropDownList3");
// Output result string based on which values are specified
if (string.IsNullOrEmpty(make))
{
Label1.Text = "Please select a make.";
}
else if (string.IsNullOrEmpty(model))
{
Label1.Text = "Please select a model.";
}
else if (string.IsNullOrEmpty(color))
{
Label1.Text = "Please select a color.";
}
else
{
Label1.Text = string.Format("You have chosen a {0} {1} {2}. Nice car!", color, make, model);
}
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string category)
{
return new CarsService().GetDropDownContents(knownCategoryValues, category);
}
}
All replies (2)
Tuesday, August 19, 2008 2:42 PM âś…Answered
"make" is typed as a DropDownList, not a String. Therefore, it cannot be used with the String.IsNullOrEmpty method.
Instead, simple check to see if "make" is null.
if (make == null)
Tuesday, August 19, 2008 2:51 PM
Thank you! That worked!