| | |
populate two dropdownlist
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 40
Reputation:
Solved Threads: 0
hi jerry i got your attachement and i build my own application just like yours but i gettin error message, just go through my my coding .
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlDataAdapter da = new SqlDataAdapter("select county_id,countryname from country_master88", con);
DataSet ds1 = new DataSet();
da.Fill(ds1, "country_master88");
dd1.DataSource = ds1.Tables["country_master88"];
dd1.DataTextField = "countryname";
dd1.DataValueField = "countyr_id";
}
protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView drv;
string countryid;
if (dd1.SelectedValue == null) return;
if (dd1.SelectedValue is DataRowView)
{
drv = (DataRowView)dd1.SelectedValue;
countryid = drv["country_id"].ToString();
}
else
countryid = dd1.SelectedValue.ToString();
if (countryid == string.Empty) return;
string sql = string.Format("SELECT stateid,statename FROM countrystate88 where county_id={0}", countryid);
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlDataAdapter da1 = new SqlDataAdapter(sql, con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "countrystate");
dd1.DataSource = ds1.Tables["countrystate88"];
dd2.DataTextField = "statename";
dd2.DataValueField = "stateid";
dd2.SelectedIndexChanged(null, null);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView drv;
string countryid;
string stateid;
if (dd2.SelectedValue == null) return;
if (dd2.SelectedValue is DataRowView)
{
drv = (DataRowView)dd2.SelectedValue;
stateid = drv["stateid"].ToString();
}
else
stateid = dd2.SelectedValue.ToString();
if (dd1.SelectedValue is DataRowView)
{
drv = (DataRowView)dd1.SelectedValue;
countryid = drv["county_id"].ToString();
}
else
countryid = dd1.SelectedValue.ToString();
if (countryid == string.Empty || stateid == string.Empty) return;
string sql = string.Format("SELECT capital FROM countrystate where county_id={0} and stateid={1}", countryid, stateid);
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
t1.Text = rdr[0].ToString();
con.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlDataAdapter da = new SqlDataAdapter("select county_id,countryname from country_master88", con);
DataSet ds1 = new DataSet();
da.Fill(ds1, "country_master88");
dd1.DataSource = ds1.Tables["country_master88"];
dd1.DataTextField = "countryname";
dd1.DataValueField = "countyr_id";
}
protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView drv;
string countryid;
if (dd1.SelectedValue == null) return;
if (dd1.SelectedValue is DataRowView)
{
drv = (DataRowView)dd1.SelectedValue;
countryid = drv["country_id"].ToString();
}
else
countryid = dd1.SelectedValue.ToString();
if (countryid == string.Empty) return;
string sql = string.Format("SELECT stateid,statename FROM countrystate88 where county_id={0}", countryid);
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
SqlDataAdapter da1 = new SqlDataAdapter(sql, con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "countrystate");
dd1.DataSource = ds1.Tables["countrystate88"];
dd2.DataTextField = "statename";
dd2.DataValueField = "stateid";
dd2.SelectedIndexChanged(null, null);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView drv;
string countryid;
string stateid;
if (dd2.SelectedValue == null) return;
if (dd2.SelectedValue is DataRowView)
{
drv = (DataRowView)dd2.SelectedValue;
stateid = drv["stateid"].ToString();
}
else
stateid = dd2.SelectedValue.ToString();
if (dd1.SelectedValue is DataRowView)
{
drv = (DataRowView)dd1.SelectedValue;
countryid = drv["county_id"].ToString();
}
else
countryid = dd1.SelectedValue.ToString();
if (countryid == string.Empty || stateid == string.Empty) return;
string sql = string.Format("SELECT capital FROM countrystate where county_id={0} and stateid={1}", countryid, stateid);
SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
t1.Text = rdr[0].ToString();
con.Close();
}
}
•
•
Join Date: Nov 2007
Posts: 40
Reputation:
Solved Threads: 0
errors for the above codding is
1. it shows error in the both dropdownlist_selectedchange
near "if (dd2.SelectedValue is DataRowView)"
the message is : The given expression is never of the provided ('System.Data.DataRowView') type
2.next error shows at "drv = (DataRowView)dd1.SelectedValue"
the message Error is: Cannot convert type 'string' to 'System.Data.DataRowView'
3.next error showas at
"dd2.SelectedIndexChanged(null, null)"
the error message is: The event 'System.Web.UI.WebControls.ListControl.SelectedIndexChanged' can only appear on the left hand side of += or -=
and the same errors for all the dropdownlist_selectedindexcanged..
just solve my problem its very urgent
thank you
raghu
1. it shows error in the both dropdownlist_selectedchange
near "if (dd2.SelectedValue is DataRowView)"
the message is : The given expression is never of the provided ('System.Data.DataRowView') type
2.next error shows at "drv = (DataRowView)dd1.SelectedValue"
the message Error is: Cannot convert type 'string' to 'System.Data.DataRowView'
3.next error showas at
"dd2.SelectedIndexChanged(null, null)"
the error message is: The event 'System.Web.UI.WebControls.ListControl.SelectedIndexChanged' can only appear on the left hand side of += or -=
and the same errors for all the dropdownlist_selectedindexcanged..
just solve my problem its very urgent
thank you
raghu
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
rahgu,
What version of c# are you using ?
There are some differences that can cause these problems.
I know you are in dire need of this, but I have to go to work in a few minutes. If you are willing to wait until tonight (California time) I will write it as an ASP application to get rid of the problems you are seeing.
In the mean time, you can modify the code I sent to be used as a Windows Application so you can see how it works. Works flawlessly here.
That may help you get it working in ASP.
I will post the APS version in about 10 hours.
--Jerry
What version of c# are you using ?
There are some differences that can cause these problems.
I know you are in dire need of this, but I have to go to work in a few minutes. If you are willing to wait until tonight (California time) I will write it as an ASP application to get rid of the problems you are seeing.
In the mean time, you can modify the code I sent to be used as a Windows Application so you can see how it works. Works flawlessly here.
That may help you get it working in ASP.
I will post the APS version in about 10 hours.
--Jerry
•
•
Join Date: Nov 2007
Posts: 40
Reputation:
Solved Threads: 0
thanks jerry i got through the coding
but the values in dropdown list i am not getting the exact way what i want,i will explain you again that if we select any country from 1stdropdownlist then it should place only selected country's states in the second dropdownlist and so on...
just tell me how many tables should i have to prepare in sql server..
thanku you jerry for your replies, i do consider tha as my best part of my job
but the values in dropdown list i am not getting the exact way what i want,i will explain you again that if we select any country from 1stdropdownlist then it should place only selected country's states in the second dropdownlist and so on...
just tell me how many tables should i have to prepare in sql server..
thanku you jerry for your replies, i do consider tha as my best part of my job
![]() |
Similar Threads
- SelectedIndexChanged in DropDownList won't trigger (VB.NET)
- asynchronous dropdownlist any idea (ASP.NET)
- Dropdownlist.... please help (C#)
- dropdownlist not firing (VB.NET)
- dropdownlist not firing (ASP.NET)
- please anybody to help Dropdownlist selected index problem (ASP.NET)
- POpulate DataGrid (VB.NET)
- retrieving ids from dynamically created controls in asp.net (ASP)
- DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: Highlight the data in the DataGrid when it is searched...
- Next Thread: need help for distributed Application
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast c# check checkbox client clock combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation excel file form format formatting forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remoting resource restore richtextbox server sleep soap socket sql sqlserver statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml





