dropdownlist
-
hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }
-
hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }
check whether you have given autopostback property to both the dropdown
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
check whether you have given autopostback property to both the dropdown
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }
-
Make sure you have wired the event up properly in your aspx page, i.e. Also, put a breakpoint at the start of your DropDownList2_SelectedIndexChanged method to see if it is being called at all.
-
hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }
i have done the same thing which u want i just use daset instead of datareader try it
protected void Page\_Load(object sender, EventArgs e) { DAL Helper = new DAL(); // DataSet ds = new DataSet(); Helper.ConnectionString = "Data Source=.\\\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Coupon Management.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; // SqlCommand txtcmd = new SqlCommand(); // commandText ="'"+txtAmount .AutoPostBack +"'"; string query = "select CouponName from CouponType"; ds = Helper.ExecuteDataSet(CommandType.Text, query, null); if (!IsPostBack) { ddlCType.DataSource = ds; ddlCType.DataValueField = "CouponName"; ddlCType.DataTextField = "CouponName"; ddlCType.DataSourceID = String.Empty; } } protected DataSet GetData(string sqlCommand) { da1 = new SqlDataAdapter(sqlCommand, cnx ); ds = new DataSet(); da1.Fill(ds ); return ds ; }
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
cnx.Open();
SqlCommand ddlcmd = new SqlCommand();
commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
ds = new DataSet();
ds = GetData(commandText);
if (ds.Tables[0].Rows.Count!=0 )
{
txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
cnx.Close();
}
} -
hii all... i hav populated the two dropdown lists from database. according to the item selected in the dropdown i want to change the respective textbox value.I hav written code it works for first dropdown but not for second.whenever i change the item in dropdownlist2 it does not show any value in its respective textbox. plz reply.. the code is: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateDDL1(); PopulateDDL2(); } } public void PopulateDDL1() { SqlCommand cmd = new SqlCommand("Select * From [Vendor]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList1.DataSource = dr; DropDownList1.DataValueField = "VendorID"; DropDownList1.DataTextField = "VendorID"; DropDownList1.DataBind(); cmd.Connection.Close(); } public void PopulateDDL2() { SqlCommand cmd = new SqlCommand("Select * From [Product]", new SqlConnection(ConfigurationManager.ConnectionStrings["BillingSystem"].ConnectionString)); cmd.Connection.Open(); SqlDataReader dr; dr = cmd.ExecuteReader(); DropDownList2.DataSource = dr; DropDownList2.DataValueField = "ProductID"; DropDownList2.DataTextField = "ProductID"; DropDownList2.DataBind(); cmd.Connection.Close(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Vendor Where(VendorID='" + DropDownList1.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox1.Text = dr["VendorName"].ToString(); } conn.Close(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string str = "Select * From Product Where(ProductID='" + DropDownList2.SelectedValue + "')"; SqlCommand cmd = new SqlCommand(str, conn); SqlDataReader dr = null; conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { TextBox3.Text = dr["ProductName"].ToString(); } conn.Close(); }
Use google
-
i have done the same thing which u want i just use daset instead of datareader try it
protected void Page\_Load(object sender, EventArgs e) { DAL Helper = new DAL(); // DataSet ds = new DataSet(); Helper.ConnectionString = "Data Source=.\\\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Coupon Management.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; // SqlCommand txtcmd = new SqlCommand(); // commandText ="'"+txtAmount .AutoPostBack +"'"; string query = "select CouponName from CouponType"; ds = Helper.ExecuteDataSet(CommandType.Text, query, null); if (!IsPostBack) { ddlCType.DataSource = ds; ddlCType.DataValueField = "CouponName"; ddlCType.DataTextField = "CouponName"; ddlCType.DataSourceID = String.Empty; } } protected DataSet GetData(string sqlCommand) { da1 = new SqlDataAdapter(sqlCommand, cnx ); ds = new DataSet(); da1.Fill(ds ); return ds ; }
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
cnx.Open();
SqlCommand ddlcmd = new SqlCommand();
commandText = "SELECT MAX(CouponTransaction.SerialEnd),CouponType.Price FROM CouponType INNER JOIN CouponTransaction ON CouponType.CouponTypeID = CouponTransaction.CouponTypeID WHERE CouponType.CouponName= '" + ddlCType.SelectedValue + "'GROUP BY CouponType.Price";
ds = new DataSet();
ds = GetData(commandText);
if (ds.Tables[0].Rows.Count!=0 )
{
txtSFrom.Text = ds.Tables[0].Rows[0][0].ToString();
Txtprice.Text = ds.Tables[0].Rows[0][1].ToString();
cnx.Close();
}
} -
your code seems to be fine.... jus check whether u have values in the database...... :)
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]