Issue in changing label color for selectedindex event of dropdownlist

Category: visual studio lightswitch

Question

Kdampuru on Tue, 22 Apr 2014 20:27:30


<p>Hi Friends,</p><p>I have 2 labels and 2 dropdownlist controls as shown in following design:</p><p>label1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dropdown1</p><p>label2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dropdown2</p><p></p><p>when&nbsp;I select dropdown1 item, other than index 0,both label1 and dropdown1 background color should change(which is working fine) and when i reset drop down to index 0,dropdown1 should reset to nocolor(working fine)&nbsp; and label1 should reset to nocolor(not working fine)

below is the code

protected

void ddlDiet_SelectedIndexChanged(object sender, EventArgs e)

    {

if (ddlDiet.SelectedIndex < 1)

        {

            lblItemcommentsmsg.Text =

"";

        }

       

else


        {

            lblItemcommentsmsg.Text = ddlDiet.SelectedItem.Value.ToString();

           

foreach (ListItem li in ddlDiet.Items)

            {

               

if (li.Selected == true)

                    li.Attributes.Add(

"style", "background:red;");

                lblDiet.Attributes.Add(

"style", "background:red;");

               

            }

           

DropDownList ddlClicked = sender as DropDownList;

           

foreach (Control control in pnlMain.Controls)

            {

               

if (control is DropDownList)

                {

                   

DropDownList ddl = control as DropDownList;

                   

if (ddl.ID != ddlClicked.ID)

                    {

                        ddl.SelectedIndex = 0;

                        lblDiet.BackColor =

default(Color);

                    }

                }

            }

            Session[

"X"] = lblItemcommentsmsg.Text;

            Session[

"ItemID"] = ddlDiet.ID;

           

string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

           

this.con = new SqlConnection(connStr);

           

this.con.Open();

            cmd =

new SqlCommand("select * from tbl_OrderSetComments where ItemID=@Item", con);

            cmd.Parameters.AddWithValue(

"Item", Session["ItemID"]);

           

DataSet ds = new DataSet();

            da =

new SqlDataAdapter(cmd);

            da.Fill(ds);

            GridView1.DataSource = ds;

            GridView1.DataBind();

        }

    }

Replies

Lareina11 on Fri, 02 May 2014 08:49:17


Is this related to Lightswitch? according to the code above, this is more suitable for asp.net forum.

http ://forums.asp.net/