Reputation: 57
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
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
Reputation: 381
For me, I would have done something like:
panel1.BorderStyle = (BorderStyle)Enum.Parse ( typeof ( BorderStyle ), DropDownList1.SelectedItem.ToString () );
Upvotes: 1
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
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