473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Convert string to HorizontalAlign value

Hi all

vs2003, .NET1.1

I would like to store alignment values in SQL Server db and then use
them in C# to set values of cells in tables. Problem is that a string
variable will not work. Is there a way to set Alignment values from a
string variable?

string sValue = "Center"; //Comes from database in real application

//Find a particular cell in a table
System.Web.UI.WebControls.TableCell c =
(TableCell)Page.FindControl(sHeadCell);

//This line wont compile
cl.HorizontalAlign = sValue;

//This is what it is looking for:
cl.HorizontalAlign =HorizontalAlign.Center

//This has run time error that it cant convert:
cl.HorizontalAlign = (HorizontalAlign)sValue;

Any idea how to get :
"cl.HorizontalAlign = sValue;"
to work?

Thanks
Jeff
May 28 '07 #1
3 5735
How about:

cl.HorizonatalAlign = Enum.Parse(typeof(HorizontalAlign), sValue,
true);

Mrac
May 28 '07 #2

I had to add :
(HorizontalAlign)
to avoid another cannot implicitly convert to type HorizontalAlign
error

cl.HorizonatalAlign =
(HorizontalAlign)Enum.Parse(typeof(HorizontalAlign ), sValue,
true);

Works very well
Thanks

jeff

On 28 May 2007 14:49:35 -0700, Marc Gravell <ma**********@gmail.com>
wrote:
>How about:

cl.HorizonatalAlign = Enum.Parse(typeof(HorizontalAlign), sValue,
true);

Mrac
May 29 '07 #3
Yup - sorry - the hazard of notepad coding ;-p But I was close...

Marc

May 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
0
by: richard | last post by:
I have been around the houses with this problem and see a few solutions but surely there is a nice neat way for me to solve this... Summary: A page that binds data to a datagrid via the...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
20
by: Niyazi | last post by:
Hi all, I have a integer number from 1 to 37000. And I want to create a report in excel that shows in 4 alphanumeric length. Example: I can write the cutomerID from 1 to 9999 as: 1 ---->...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
6
by: compboy | last post by:
Can anyone help me about this. I have been trying all the ways I knew and I could find but just didnt work. I have tried: using itoa but it says that it doesnt have that function. and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.