更新时间:2022-06-23 16:47:15
您能否在此声明之前检查StringDictionary国家/地区是否具有价值.
CountryId = Convert.ToInt32(country.ToString());
为了获得用户选择的值,您必须使用
在下面的语句中使用country ["state"]代替country.ToString().
CountryId = Convert.ToInt32(country.ToString());
Could you please check if the StringDictionary country, has value before this statement.
CountryId = Convert.ToInt32(country.ToString());
Inorder to get the value selected by the user you have to use
country["state"] instead of country.ToString() in the below statement.
CountryId = Convert.ToInt32(country.ToString());
正如你所说,我也尝试过这种方法,但是却得到了同样的错误.我在页面代码后面的代码如下:
as u said,i tried that way also,but getting the same error.my code behind page code is like:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Web.Services;
public partial class CascadingDropDown : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(),
System.Web.Script.Services.ScriptMethodAttribute()]
public static AjaxControlToolkit.CascadingDropDownNameValue[]
GetDropDownContents(string knownCategoryValues, string category)
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["ajax"].ConnectionString);
sqlcon.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from Country", sqlcon);
da.Fill(dt);
List values = new List();
for (int i = 0; i < dt.Rows.Count; i++)
{
int CountryId = (int)dt.Rows[i]["countryid"];
string Countryname = (string)dt.Rows[i]["country"];
values.Add(new AjaxControlToolkit.CascadingDropDownNameValue(Countryname, CountryId.ToString()));
}
return values.ToArray();
}
[System.Web.Services.WebMethodAttribute(),
System.Web.Script.Services.ScriptMethodAttribute()]
public static AjaxControlToolkit.CascadingDropDownNameValue[]
GetDropDownContents2(string knownCategoryValues, string category)
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["ajax"].ConnectionString);
int CountryId;
StringDictionary categoryvalues = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
CountryId = Convert.ToInt32(categoryvalues["state"]); //CountryId = Convert.ToInt32(categoryvalues["country"]);
sqlcon.Open();
DataTable dt1 = new DataTable();
SqlDataAdapter da1 = new SqlDataAdapter(" select * from State where countryid = @ CountryId", sqlcon);
da1.Fill(dt1);
sqlcon.Close();
List statevalues = new List();
for (int i = 0; i < dt1.Rows.Count; i++)
{
int stateid = (int)dt1.Rows[i]["stateid"];
string statename = (string)dt1.Rows[i]["state"];
statevalues.Add(new AjaxControlToolkit.CascadingDropDownNameValue(stateid.ToString(), statename.ToString()));
}
return statevalues.ToArray();