user2177768
user2177768

Reputation: 57

How can I change border style in a panel?

I have a dropdownlist that has a list of border style names like "Dotted,Solid,Groove..." I need to change borderstyle , so tried something like this

Panel1.BorderStyle = DropDownList1.SelectedItem.ToString();

this how i fill the dropdownlist DropDownList3.DataSource = Enum.GetValues(typeof(BorderStyle));

But it doesn't work.

Upvotes: 1

Views: 4892

Answers (5)

MethodMan
MethodMan

Reputation: 18863

Will this work for you

 panel1.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle),
    DropDownList1.SelectedItem.ToString());

You will need to add some additional code checks on your side just in case the BorderStyle is not found

Referenced from MSDN: WebControl BorderStyle

Upvotes: 1

rut0.wut
rut0.wut

Reputation: 381

For me, I would have done something like:

panel1.BorderStyle = (BorderStyle)Enum.Parse ( typeof ( BorderStyle ), DropDownList1.SelectedItem.ToString () );

Upvotes: 1

CloudyMarble
CloudyMarble

Reputation: 37576

I did not try it but maby you provide an Item collection with the real values like:

 System.Web.UI.WebControls.BorderStyle.Dotted
 System.Web.UI.WebControls.BorderStyle.Solid
 etc. 

then try something like:

Panel1.BorderStyle = DropDownList1.SelectedItem;

Upvotes: 0

Michael Ross
Michael Ross

Reputation: 570

panel1.BorderStyle = BorderStyle.Fixed3D;

Upvotes: 0

Bala R
Bala R

Reputation: 109027

Try something like this

string selectedStyle = DropDownList1.SelectedItem.ToString();

if (selectedStyle == "Dotted")
{
    Panel1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Dotted;
}
else if (selectedStyle == "Solid")
{
    Panel1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
}
// and so on ...

Upvotes: 2

Related Questions