private void cbo_Country_SelectedIndexC
hanged(obj
ect sender, EventArgs e)
{
// create an array of provinces
WebSUtil.StateProvince[] stateprovinceArr;
// create a new object srvCountryCode
WebSUtil.SrvUtil srvCountryCode = new WebSUtil.SrvUtil();
if (this.cbo_Country.Selected
Index != -1)
{
if (cbo_Province.DataSource != null)
((DataTable)cbo_Province.D
ataSource)
.Clear();
// Populate the array of provinces
stateprovinceArr = srvCountryCode.GetProvince
List(Conve
rt.ToDecim
al(this.cb
o_Country.
SelectedVa
lue));
if (stateprovinceArr != null)
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("id");
for (int i = 0; i < stateprovinceArr.Length; i++)
{
DataRow dr = dt.NewRow();
dr["name"] = stateprovinceArr[i].Name;
dr["id"] = stateprovinceArr[i].Id.ToS
tring();
dt.Rows.Add(dr);
}
this.cbo_Province.DataSour
ce = dt;
this.cbo_Province.DisplayM
ember = "name";
this.cbo_Province.ValueMem
ber = "id";
}
}
}
On the first start on the app it crashes on the first start. There must be a fix for this.
stateprovinceArr = srvCountryCode.GetProvince
List(Conve
rt.ToDecim
al(this.cb
o_Country.
SelectedVa
lue));
Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.
"Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'."
I have this in the Load Form:
private void InitializeDropDownListCoun
try(WebSUt
il.SrvUtil
srvCountryCode)
{
WebSUtil.CountryCode[] countryArr = srvCountryCode.GetCountryL
ist();
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Columns.Add("id");
for (int i = 0; i < countryArr.Length; i++)
{
DataRow dr = dt.NewRow();
dr["name"]=countryArr[i].N
ame;
dr["id"]=countryArr[i].Id.
ToString()
;
dt.Rows.Add(dr);
}
this.cbo_Country.DataSourc
e=dt;
this.cbo_Country.DisplayMe
mber="name
";
this.cbo_Country.ValueMemb
er="id";
}
Start Free Trial