0

I would like ask if you could help me with my codes as I don't get the result that I want which is to load the details of a particular paper from drop down list.

Currently, when the page loads, the details of the selected item will load up. But when I try to choose another item from the drop down list, corresponding details won't show up, the previous one still remains instead.

Under the properties of drop down list, I also set autopostback to yes so that it will automatically load the corresponding details of the item selected.

Please see codes below

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GetPaper();
        GetInk();

        GetPaperDetails(ddlPaperName.SelectedItem.Value);
        //pnlPrinting.Visible = true;
    }
}
protected void btnCompute_Click(object sender, EventArgs e)
{

}
protected void btnCancel_Click(object sender, EventArgs e)
{

}

private void GetPaper()
{
    con.Open();
    SqlCommand com = new SqlCommand();
    com.Connection = con;
    com.CommandType = CommandType.Text;
    com.CommandText =
        "SELECT * FROM Papers";

    SqlDataReader data = com.ExecuteReader();

    ddlPaperName.DataSource = data;
    ddlPaperName.DataValueField = "PaperID";
    ddlPaperName.DataTextField = "PaperName";
    ddlPaperName.DataBind();

    data.Close();
    con.Close();     
}

private void GetPaperDetails(string paper)
{
    con.Open();
    SqlCommand com = new SqlCommand();
    com.Connection = con;
    com.CommandType = CommandType.Text;
    com.CommandText =
        "SELECT * FROM Papers WHERE PaperID=" + paper;

    SqlDataReader data = com.ExecuteReader();

    while (data.Read())
    {
        lblPaperPrice.Text = data["PaperPrice"].ToString();
        lblDescription.Text = data["PaperDescription"].ToString();
        lblSpecification.Text = data["PaperSpecification"].ToString();
        imgPaper.ImageUrl = "../" + data["PaperImage"].ToString();
    }
    data.Close();
    con.Close();
}


private void GetInk()
{
    con.Open();
    SqlCommand com = new SqlCommand();
    com.Connection = con;
    com.CommandType = CommandType.Text;
    com.CommandText =
        "SELECT * FROM Inks";

    SqlDataReader data = com.ExecuteReader();

    ddlPaperName.DataSource = data;
    ddlPaperName.DataValueField = "InkID";
    ddlPaperName.DataTextField = "InkName";
    ddlPaperName.DataBind();

    while (data.Read())
    {
        lblInkPrice.Text = data["InkPrice"].ToString();
    }
    data.Close();
    con.Close();
}
protected void ddlPaperName_SelectedIndexChanged(object sender, EventArgs e)
{
        GetPaperDetails(ddlPaperName.SelectedItem.Value);
}

Looking forward to your feedback here. Thanks!

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
Charles Tan
  • 93
  • 2
  • 12

2 Answers2

0

Set AutoPostBack property to true of your drop down list.

Monika
  • 2,172
  • 15
  • 24
  • Hi, autopostback is set to true already :-( thats what i meant in the above description, "autopostback is set to yes" – Charles Tan Oct 23 '13 at 14:07
0

us this code, for that,

 if (!IsPostBack == true)
            {

                drpdownaccountnamebind();
                drpdowncountrynamebind();

            }

i hope this will be helpful,

ketan italiya
  • 296
  • 1
  • 5
  • 23