2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by sania khan
0

If you want to check a radio button based on some value you would use

RadioButtonList1.Items[index].Selected = true

The Text method would not whether it was checked or not. It alters the text assigned to the item.

0

RadioButtonList1.Items[index].Selected = true

Actually in my Project RadiobuttonLsit has two items ..1st one is "Spot Purchase"and 2nd one is "Tendor Purchase". and there is a column "Type_Of_Purchase (nchar) "in the database .I want to read this column and then if this return "Tendor Purchase",then i want to check "Tendor Purchase" item in the radiobuttonList else i want to check "Spot Purchase" item in the radiobuttonList . help me to solve my problem :(

0

Actually in my Project RadiobuttonLsit has two items ..1st one is "Spot Purchase"and 2nd one is "Tendor Purchase". and there is a column "Type_Of_Purchase (nchar) "in the database .I want to read this column and then if this return "Tendor Purchase",then i want to check "Tendor Purchase" item in the radiobuttonList else i want to check "Spot Purchase" item in the radiobuttonList . help me to solve my problem :(

Edited by sania khan

0

OK, then query your database and retrieve that column. Then simply check it with an if statment.

string result = // place your retrieved column here
if(result == "Spot Purchase) {
   RadionButtonList.Items[0].Selected = true;
} elseif(result == "Tendor Purchase") {
   RadioButtonList.Items[1].Selected = true;
}
0
//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;}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.