|
godfetish wrote: .I'm new to ASP.NET
And I know zilch about it.
I'll bet there are a lot of people over in the ASP.NET Forum that do though.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Don't expect the help with ASP.NET, asked for help with serializing a List in C#, but thanks for reading the first sentance.
|
|
|
|
|
Sorry about that. My eyes are tired, that's my excuse, and I'm sticking to it.
solution:
public static void Main(String[] args)
{
List<Employee> mp = new List<Employee>();
Employee e = new Employee();
e.EmpId = 10;
e.EmpName = "Omkumar";
mp.Add(e);
e = new Employee();
e.EmpId = 11;
e.EmpName = "this";
mp.Add(e);
e = new Employee();
e.EmpId = 12;
e.EmpName = "is a";
mp.Add(e);
e = new Employee();
e.EmpId = 13;
e.EmpName = "test";
mp.Add(e);
mp.Add(e);
You do realise you will get two 13 employees, because of the last line.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The output of the sample project is:
Writing Employee Information<br />
Reading Employee Information<br />
Employee Id: 13<br />
Employee Name: test<br />
Employee Id: 13<br />
Employee Name: test<br />
Employee Id: 13<br />
Employee Name: test<br />
Employee Id: 13<br />
Employee Name: test<br />
Employee Id: 13<br />
Employee Name: test<br />
Press any key to continue . . .
So, yes, two EId's of 13 should be there, by design or by fault...not 5 of them when deserialized.
I see that the de/serialization is only calling the get/set in the class object one time each way. Not 5 times, once for each record! This is an interesting problem...
|
|
|
|
|
I copied your code to a new Console Application and ran it. I got the result that you have just posted. Then I made the modifications, as in my previous post, and I got:
Writing Employee Information
Reading Employee Information
Employee Id: 10
Employee Name: Omkumar
Employee Id: 11
Employee Name: this
Employee Id: 12
Employee Name: is a
Employee Id: 13
Employee Name: test
Employee Id: 13
Employee Name: test
BTW When you post code snippets, if you are currently highlighting your code and then clicking on the 'inline code' widget (immediately above the text entry box) would you please use the 'code block' widget next to it. (explanation follows)
If on the other hand, you are typing in your 'code' tags could you please use 'pre' in place of 'code'.
EXPLANATION:
The 'code' tags give the horrible red and blue code colouration, which is very hard on the eyes and is one of the reasons I didn't read all of your original post. I'm being serious here, it actually makes my eyes hurt, and I know that applies to other CP members as well.
The 'pre' tags give much more restful colouring and what's more it preserves the formatting (well mostly) of your code, making it much easier to read.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You are right! Thanks Henry.
jrk
|
|
|
|
|
Pleasure!
Sorry again, for the misunderstanding.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I'm using a cascading dropdownlist using three tables. the code below works fine if my primary keys are numeric(integer) but my business rules want the primary keys to be alphernumeric(string).
[WebMethod]
public CascadingDropDownNameValue[] GetColors(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int colorId;
if (!kv.ContainsKey("Model") || !Int32.TryParse(kv["Model"],out colorId))
{
return null;
}
dsModelColorsTableAdapters.ModelColorsTableAdapter adapter = new dsModelColorsTableAdapters.ModelColorsTableAdapter();
dsModelColors.ModelColorsDataTable colors = adapter.GetColorsByModelId(colorId);
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
foreach (DataRow dr in colors)
{
values.Add(new CascadingDropDownNameValue((string)dr["ColorName"], dr["ColorID"].ToString()));
}
return values.ToArray();
}
How do I use my string primary key using the above code?
Please help an ajax technology adict.
ML Lingwati
|
|
|
|
|
You are aware that we have both 'Web Development' and 'ASP.NET' Forums?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all,
I am trying to print a string that has alot of HTML tags in it. When I make use of the HTML visualizer, I can see that the output is correct. But how can I print it without showing the HTML tags, and only the correct format / output.
Many thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Set that string to a web browser control and call Print() method on that.
|
|
|
|
|
Thanks for the response. This can only be done in a WinForms applicaiton and not in ASP.NET
Something like this then:
using (WebBrowser b = new WebBrowser())
{
b.Navigate("about:blank");
b.Document.Title = pageTitle;
b.Document.Write(pageContent);
b.ShowPageSetupDialog();
b.ShowPrintPreviewDialog();
b.ShowPrintDialog();
}
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Well, do you want to do this in a windows/web application? Since you posted this on C# forum, I assumed you are on a windows application. If it is ASP.NET, you assign the string to a literal control and write the JS window.print() to the page using ClientScriptManager.RegisterClientScript() method. This will force the browser to display a print dialog box.
|
|
|
|
|
Hello
Is there any way to change the type of a column in a binded datagridview
I set the datasource of a datagridview from a datatable
This datatable contain two column needed for my purpose : an id and a text
I have another table Fruit
Each Fruit have an Id and A text
Of course I can also bind that table to a ComboBox
At run time in the DGV I need to show a column whith the fruit related to each row but I need to be able to get a combo cell on that column to chose another fruit from the fruit table
Is it possible ?
How can I do that
Thank for any help
|
|
|
|
|
We had to update the 3rd party application to allow null values for the specific enum fields. Flushed the mid-tier cache, updated the web reference in VS, updated the code to allow null (Incident_WS.StatusType? Status;) and it works.
-----
I'm trying to retrieve information from a web service. Some of the output parameters are enums and do not have a value in the database. How can I handle a null value in the code? I'm using C# 2008 with the 2.0 framework, if needed I can use a newer framework.
My example code (the actual web service has 9 enums):
Incident_WS.Incident_WSService ws = new Incident_WS.Incident_WSService();
Incident_WS.AuthenticationInfo auth = new Incident_WS.AuthenticationInfo();
auth.userName = "TEST";
auth.password = "WS_TEST";
ws.AuthenticationInfoValue = auth;
string Incident_Number = "INC000000007371";
Incident_WS.StatusType Status;
ws.HelpDesk_Query_Service(Incident_Number, out Status);
From the web service:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3053")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:HPD_IncidentInterface_WS")]
public enum StatusType {
New,
Assigned,
[System.Xml.Serialization.XmlEnumAttribute("In Progress")]
InProgress,
Pending,
Resolved,
Closed,
Cancelled,
}
Thanks in advance!
modified on Wednesday, August 26, 2009 11:54 AM
|
|
|
|
|
How about adding a new item to the enum something like None ?
public enum StatusType {
New,
Assigned,
[System.Xml.Serialization.XmlEnumAttribute("In Progress")]
InProgress,
Pending,
Resolved,
Closed,
Cancelled,
None
} If there is no value, just set StatusType.None .
|
|
|
|
|
We're connecting to a 3rd party database (BMC Remedy) and do not have the option to adding None to the list. A blank value is valid in the client. I don't know why there is not a blank option in the enum.
|
|
|
|
|
Good morning guys,
I need to write a program to validate the field values of several tables, and report which values don't comply with the validation.
So, let us suppose we need to validate only one field per each table.
The main procedure fetches all rows for that specific table/field, and calls a "validation function" to validate if that particular field for that table is valid.
We can end up with several validation functions which is OK since each validation is unique, but once I compiled the program, how can we plug a new validation functions to it?
The program will basically ask for 2 parameters: the table name and field name to validate, but how can we inject the "validation function" dynamically?
Open to ideas, suggestions
Thanks,
...Alex
|
|
|
|
|
Well, that's a plugin / extensibility question, if I'm not mistaken!
How about you use MEF[^] then?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Thanks for your prompt reply. I guess it is considered an extension/plugin; however, MEF is still in development according to the MEF site.
I guess I'd end up adding new validation functions and recompiling every time 
|
|
|
|
|
well, it's an advanced stage of development..
much like Google apps in beta for years!
I'm using them with quite good satisfaction already now!
There is also http://www.mono-project.com/Mono.Addins[^]
If none of that please you I guess you have to write your own plugin mechanism...
You might investigate the following method:
Assembly.Load()
Assembly.GetType()
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
The way to do this is to create a common interface and let all your validation classes implement this interface.
public interface IValidator
{
bool Validate();
} Keep all the available validation classes full name in the configuration file. You can use reflection to create instance of these classes. To create instance, work with Activator.CreateInstance() method. Cast the return value of Activator.CreateInstance() to IValidator and call Validate() method on this object to perform validation.
You can just modify the configuration file when new validator has to be added. No program recompilation is required.
|
|
|
|
|
N a v a n e e t h wrote: Keep all the available validation classes full name in the configuration file.
Can you elaborate on this or provide a link for details on how to accomplish this? Not sure which "configuration file" you are referring to
N a v a n e e t h wrote: You can use reflection to create instance of these classes. To create instance, work with Activator.CreateInstance() method. Cast the return value of Activator.CreateInstance() to IValidator and call Validate() method on this object to perform validation.
Got it![^]
N a v a n e e t h wrote: You can just modify the configuration file when new validator has to be added. No program recompilation is required.
That's what I am trying to accomplish!
If I understand this correctly, once I have all possible validation classes implemented with the same interface... should I just leave the *.cs files by themselves or do I need to compile those as well so the main class can load them? Even though I like your approach, it's a little confusing for me to picture it.
If you happen to have a small working project similar to what we are trying to accomplish here, can you share it?
Thanks for you great feedback!
...Alex
|
|
|
|
|
neualex wrote: If I understand this correctly, once I have all possible validation classes implemented with the same interface... should I just leave the *.cs files by themselves or do I need to compile those as well so the main class can load them?
Here is what I meant,
1 - You have created the application with 3 validation classes all implements IValidator interface.
2 - I assume you will have a configuration file. In windows applications, app.config can be used or a settings file.
3 - You need to add all the validation classes to this configuration file so that reflection can load it. By full name, I meant the fully qualified name including the assembly name where the classes resides.
4 - Read the configuration file and load the specified classes with Activator.CreateInstance() and cast it to IValidator to call Validate() on it.
neualex wrote: If you happen to have a small working project similar to what we are trying to accomplish here, can you share it?
Unfortunately, I don't have.
Here is a sample from which you can understand what I meant. For simplicity, I assume all your validation methods has a signature like bool Validate(object itemToValidate) . So the first step is to define the interface.
public interface IValidator
{
bool Validate(object itemToValidate);
} Let us create a simple validation class named FirstValidation.
public sealed class FirstValidation : IValidator
{
public bool Validate(object itemToValidate)
{
}
} Next validation class
public sealed class SecondValidation : IValidator
{
public bool Validate(object itemToValidate)
{
}
} Here is the entry in app.config looks like. I am using settings file with the application scope. So it will generate entries like the below. Text in bold are the class names which we have to load using reflection.
<applicationSettings>
<TestApplication.Settings1>
<setting name="ValidationClasses" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Test.First</string>
<string>Test.Second</string>
</ArrayOfString>
</value>
</setting>
</TestApplication.Settings1>
</applicationSettings> In this case, Test is my namespace name. When you specify the class name, it has to follow a format like NamespaceName.ClassName . Here is how you activate the class instance
foreach (string s in Settings1.Default.ValidationClasses)
{
Type type = Type.GetType(s);
IValidator validator = (IValidator)Activator.CreateInstance(type);
validator.Validate();
} When the validation classes are in different assembly, you need to use the other overload of Activator.CreateInstance which takes assembly name.
Hope this made it clear.
|
|
|
|
|
Great! Yes, it is clear!
One question, on your approach it seems we got to have all possible "validation classes" defined before compilation if the method which calls these classes is in the same assembly.
So, how would you handle "future validation classes" that we don't know we need yet.
I guess from your explanation, we could separate the main program which calls these "validation classes" in one assembly, and the validation classes in another assembly.
So, future validation classes get added to the second assembly and recompiled for the first assembly to consume -we need to add this new validation class to the config file as well.
Am I interpreting this correctly or I missed something?
Thanks for your great feedback!
...Alex
|
|
|
|