//Check radiobutton list based on the data retrieve from the database
//This is also not working.. This does not select any item of the RadioButtonList1.. and also not giving any error...
//Here is my code
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string selectSQL;
selectSQL = "SELECT * FROM Books_Magazines ";
selectSQL += "WHERE Ref#='" + DropDownList2.SelectedItem.Text + "'";
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.;Initial Catalog=ecsd1;User ID=sa;Password=786";
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataReader reader;
// Try to open database and read information.
try
{
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
TextBox1.Text = reader["Book_Name"].ToString();
TextBox2.Text = reader["Author_Name"].ToString();
TextBox4.Text = reader["Publisher"].ToString();
TextBox3.Text = reader["Ref#"].ToString();
txtEventDate.Text = reader["Date_Of_Purchase"].ToString();
TextBox6.Text = reader["Vendor_Supplier"].ToString();
TextBox7.Text = reader["Price"].ToString();
string result = reader["Type_Of_Purchase"].ToString();// place your retrieved column here
if(result == "Spot Purchase")
{
RadioButtonList1.Items[0].Selected = true;
}
else if(result == "Tendor Purchase")
{
RadioButtonList1.Items[1].Selected = true;
}
reader.Close();
lblStatus.Text = "";
}
catch (Exception err)
{
lblStatus.Text = "Error in displaying data. ";
lblStatus.Text += err.Message;
}
finally
{
con.Close();
}
}
> string result = // place your retrieved column hereif(result == "Spot Purchase) { RadionButtonList.Items[0].Selected = true;} elseif(result == "Tendor Purchase") { RadioButtonList.Items[1].Selected = true;}