// Initialize Connection
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT ECPLensType1.*, ECPLenses.Material FROM ECPLenses INNER JOIN ECPLensType1 ON ECPLensType1.LensID = ECPLenses.LensID WHERE ECPLensType1.LensID=" + cboODMaterial.SelectedItem.Value, conn);
// Error handling for database code
try
{
//Open the connection
conn.Open();
//Close the reader
reader.Close();
}
catch
{
lblError.Text = "* An error occurred retrieving a list of Available Lenses..";
}
finally
{
//Close the connection
conn.Close();
}
}
eyeguy1
Member
2 Points
61 Posts
Re: HELP.. Filling Second DropDownList based on parameters of selection in another DropDown List...
May 07, 2012 06:07 PM|LINK
<asp:DropDownList ID="cboODMaterial" runat="server" AutoPostBack="true" OnSelectedIndexChanged="btnSelectOD_Click1"
style="z-index: 1; left: 168px; top: 18px; position: absolute; width: 143px; height: 22px"
TabIndex="6">
</asp:DropDownList>
<asp:DropDownList ID="cboODStyle" runat="server"
style="z-index: 1; left: 409px; top: 17px; position: absolute; width: 248px"
TabIndex="7" AppendDataBoundItems="True" AutoPostBack="True">
</asp:DropDownList>
Here is more of the code behind file
protected void Page_Load(object sender, EventArgs e)
{
if (Page.Session["Username"] == null && Page.Session["Username"] == null)
{
Response.Redirect("ECPLogin.aspx");
}
lblWelcome.Text = "Welcome back " + Session["Username"];
lblAccountNumber.Text = Session["Username"].ToString();
if (!IsPostBack)
LoadLensMaterialList();
if(!IsPostBack)
btnSelectOD_Click1(null, null);
}
private void LoadLensMaterialList()
{
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.Config
string connectionString =
ConfigurationManager.ConnectionStrings["ValueVision"].ConnectionString;
// Initialize Connection
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT LensID, Material FROM ECPLenses", conn);
// Error handling for database code
try
{
//Open the connection
conn.Open();
reader = comm.ExecuteReader();
cboODMaterial.DataSource = reader;
cboODMaterial.DataValueField = "LensID";
cboODMaterial.DataTextField = "Material";
cboODMaterial.DataBind();
//Close the reader
reader.Close();
}
catch
{
lblError.Text = "* An error occurred retrieving a list of Available Lenses..";
}
finally
{
//Close the connection
conn.Close();
}
}
protected void btnSelectOD_Click1(object sender, EventArgs e)
{
{
// Response.Write("Filling");
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.Config
string connectionString =
ConfigurationManager.ConnectionStrings["ValueVision"].ConnectionString;
// Initialize Connection
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT ECPLensType1.*, ECPLenses.Material FROM ECPLenses INNER JOIN ECPLensType1 ON ECPLensType1.LensID = ECPLenses.LensID WHERE ECPLensType1.LensID=" + cboODMaterial.SelectedItem.Value, conn);
// Error handling for database code
try
{
//Open the connection
conn.Open();
reader = comm.ExecuteReader();
cboODStyle.DataSource = reader;
cboODStyle.DataValueField = "LensID";
cboODStyle.DataTextField = "Description";
cboODStyle.DataBind();
//Close the reader
reader.Close();
}
catch
{
lblError.Text = "* An error occurred retrieving a list of Available Lenses..";
}
finally
{
//Close the connection
conn.Close();
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand comm;
string connectionString = ConfigurationManager.ConnectionStrings["ValueVision"].ConnectionString;
conn = new SqlConnection(connectionString);
comm = new SqlCommand(
"INSERT INTO OrdersDB (AccountNumber, Username, Lastname, Firstname, JobType, OrderType, ODMaterial, ODStyle, " +
........................................................................................