for example i am having a drop down box ,
eg: i am selecting product name in drop down, ie:ice cream
The price of the ice cream have to display in text box , that data have to retrieve from database.
This is the code , which i used , but data not retrieve :
I need the solution , i need your help.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
public string connectionString = WebConfigurationManager.ConnectionStrings["conWeb"].ConnectionString;
public SqlConnection cn;
public SqlCommand cmd;
#region DECLARATIONS
private string mailTo;
private string mailFrom;
private string mailMessage;
private string mailSubject;
private string mailReply;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
cn = new SqlConnection(connectionString);
string strQuery = "Select id,Tabletname,Price from tb_addproduct";
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
ddllist.DataSource = ds;
ddllist.DataTextField = "Tabletname";
txtprice.ReadOnly.ToString();
ddllist.DataValueField = "id";
ddllist.DataBind();
ddllist.Items.Insert(0, "--Select Tablet--");
}
catch (Exception ex)
{
throw ex;
}
}
}
protected void btsubmit_Click(object sender, EventArgs e)
{
if (SubmitDetails())
{
lblMsg.Visible = true;
lblMsg.ForeColor = System.Drawing.Color.Blue;
lblMsg.Font.Bold = true;
lblMsg.Font.Size = 10;
lblMsg.Text = "Your request has been submitted";
ddllist.Text = "";
Qty1.Text = "";
txtprice.Text = "";
email.Text = "";
ads.Text = "";
}
else
{
lblMsg.Visible = true;
lblMsg.ForeColor = System.Drawing.Color.Red;
lblMsg.Font.Bold = true;
lblMsg.Font.Size = 14;
lblMsg.Text = "Try Again Sometime Later";
}
}
private bool SubmitDetails()
{
try
{
mailTo = "vinoth.lakshman86@gmail.com";
mailFrom = email.Text;
mailSubject = "Order Details";
mailReply = email.Text;
mailMessage = "<table><tr><td height='4'> </td></tr><tr><td></td></tr><tr><td height='8'></td></tr><tr><td align='center'><table><tr><td>Tablet 1:</td><td>"
+ txtprice.Text + "</td></tr><tr><td>Price:</td><td>"
+ ddllist.Text + "</td></tr><tr><td>Quantity:</td><td>"
+ Qty1.Text + "</td></tsr><tr><td>Emailid:</td><td>"
+ email.Text + "</td></tsr><tr><td>Address:</td><td>"
+ ads.Text + "</td></tr></table></td></tr></table>";
MailMessage myMailMessage = new MailMessage(mailFrom, mailTo);
myMailMessage.Subject = mailSubject;
myMailMessage.Body = mailMessage;
myMailMessage.IsBodyHtml = true;
myMailMessage.ReplyTo = new MailAddress(mailReply);
System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("vinoth.lakshman86@gmail.com", "test1234");
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(myMailMessage);
return true;
}
catch
{
return false;
}
}
protected void ddllist_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cn = new SqlConnection(connectionString);
string strQuery = "Select id,Price from tb_addproduct where Price='" + txtprice.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
da.SelectCommand.Parameters.AddWithValue("id", Convert.ToInt32(ddllist.SelectedValue.ToString()));
}
catch (Exception ex)
{
throw ex;
}
}
void FullGrid()
{
try
{
cn = new SqlConnection(connectionString);
string strQuery = "Select id,Tabletname,Price from tb_addproduct where pid='" + ddllist.SelectedItem.Value + "' and Price ='" + txtprice.Text + "'" ;
SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
}
catch (Exception ex)
{
throw ex;
}
}
public void datashow()
{
string nameshow = ddllist.Text.ToString().Trim();
cmd.CommandText = "select * from tb_addproduct where Tabletname='" + nameshow + "' ";
cmd.Connection = cn;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
cn.Open();
cmd.ExecuteNonQuery();
ddllist.DataSource = ds;
ddllist.DataBind();
cn.Close();
}
}