Prev: Popup if change in gridview
Next: Hotfix
From: Andr� Freitas on 18 Jan 2010 08:26 >>>>> Whats the best way to implement a dictionary like class who gets 3 >>>>> columns. Like: >>>>> >>>>> "name", "regex", "error msg" >>>>> >>>>> Or >>>>> >>>>> "name", "reg" and "name", "error msg" > > >>>> A Dictionary is composed of two parts - a key and a value - so neither >>>> of the above would fit into a Dictionary directly >>>> >>>> It would be helpful if you could explain a little more about what you >>>> are trying to achieve... > > >>> Well, I'm trying to set default rage and default error message to all >>> kinds of inputs in the project, since today there's a mess, same fields >>> validated with different rage. >>> >>> I can have 2 Dictionaries... one for regular expressions, one for error >>> messages, but I'm not sure about the best way to implement it in a easy >>> way to use.. > >> Assuming that the data is unlikely to change very often, I'd probably use >> a DataTable which I'd create and populate in Application_Start and store >> in Application memory. Then I'd just use standard ADO.NET functionality >> on it. I do this for (almost) static data e.g. country codes, currency >> codes etc... > > > U meant something like that: > > public string returnregexp(string fieldname) > { > /* > declare the datatable here and populate the datatable here > return the correct field using probaly a datatable.select > or using a dictionary like functionality > */ > } > > Regards, > Sorry about double post, theres no way to avoid that. And about using a static method, that i can access without a instance of then? Will it be expensive for the server to keep it in memory?
From: Mark Rae [MVP] on 18 Jan 2010 08:40 "Andr� Freitas" <andrefreitas> wrote in message news:ePtpe$DmKHA.2188(a)TK2MSFTNGP04.phx.gbl... > You meant something like that: > > public string returnregexp(string fieldname) > { > /* > declare the datatable here and populate the datatable here > return the correct field using probaly a datatable.select > or using a dictionary like functionality > */ No, I mean something like this: protected void Application_Start(Object sender, EventArgs e) { DataTable dtRegex = new DataTable(); // add the columns // set primary key and indexes, as required // populate the data Application["dtRegex"] = dtRegex; } Then, whenever you need to use it: using (DataTable dtRegex = (DataTable)Application["dtRegex"]) { // use standard ADO.NET functionality to find the record(s) you need } -- Mark Rae ASP.NET MVP http://www.markrae.net
From: Mark Rae [MVP] on 18 Jan 2010 08:41 "Andr� Freitas" <andrefreitas> wrote in message news:%23JuGYHEmKHA.3972(a)TK2MSFTNGP04.phx.gbl... > Sorry about double post, theres no way to avoid that. I don't understand what you mean... > And about using a static method, that I can access without a instance of > then? Will it be expensive for the server to keep it in memory? See previous post for an example of usage. And no, it won't be expensive for the server to keep it in memory unless the DataSet is enormous... -- Mark Rae ASP.NET MVP http://www.markrae.net
From: Göran Andersson on 19 Jan 2010 07:20 Andr� Freitas wrote: > Whats the best way to implement a dictionary like class who gets 3 columns. > Like: > > "name", "regex", "error msg" > > Or > > "name", "reg" and "name", "error msg" > > Regards, > Andr� > Make a custom class that contains a regular expression and an error message, and use in a dictionary: public class InputSettings { public string Regex { get; private set; } public string ErrorMessage { get; private set; } public InputSettings(string regex, string errorMessage) { Regex = regex; ErrorMessage = errorMessage; } } var settings = new Dictionary<string, InputSettings>(); settings.Add( "name", new InputSettings( ".+", "Name has to be at least three characters." ) ); settings.Add( "email", new InputSettings( "@", "The email address is incomplete." ) ); Now you can efficiently look up the settings based on the control name. -- G�ran Andersson _____ http://www.guffa.com
From: Andr� Freitas on 19 Jan 2010 11:38
>> Whats the best way to implement a dictionary like class who gets 3 >> columns. Like: >> >> "name", "regex", "error msg" >> >> Or >> >> "name", "reg" and "name", "error msg" >> >> Regards, >> Andr� > Make a custom class that contains a regular expression and an error > message, and use in a dictionary: > > public class InputSettings { > > public string Regex { get; private set; } > public string ErrorMessage { get; private set; } > > public InputSettings(string regex, string errorMessage) { > Regex = regex; > ErrorMessage = errorMessage; > } > > } > > var settings = new Dictionary<string, InputSettings>(); > settings.Add( > "name", new InputSettings( > ".+", "Name has to be at least three characters." > ) > ); > settings.Add( > "email", new InputSettings( > "@", "The email address is incomplete." > ) > ); > > Now you can efficiently look up the settings based on the control name. > > -- > G�ran Andersson > _____ > http://www.guffa.com Can you show me how can I use it? Thank you. |