|
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
|
|
|
|
|
neualex wrote: Am I interpreting this correctly
Almost.
Usually when you develop and package the application, there will be some default validation classes which are known at compile time. That can be created with your project and have in the same assembly. For future validation classes, you can have it on a separate assembly and supply only that assembly and modify the configuration file to add this new class.
|
|
|
|
|
Gotcha! Thanks for your outstanding feedback!
...Alex
|
|
|
|
|
I am filling my datatable initially and databinding it to data gridview.code is written in button_click event.I am selecting an item from dropdownlist and when the button is clicked it is getting stored in the table.My problem is that the secondly selected item from dropdownlist is overwriting the first selected item instead of appending in the new row.I know some looping has to be done, but how and where?
OleDbCommand pay_cmd2 = new OleDbCommand("select group_details.Group,description_details.Description,description_details.Unit_price from group_details,description_details where description_details.Description='" + descrptndpdnlt .SelectedItem .Value + "' AND group_details.Group_id=(select Group_id from description_details where Description='" + descrptndpdnlt .SelectedItem .Value + "')", con2);
This is my code
da_pay.SelectCommand = pay_cmd2;
da_pay.Fill(ds_pay ,"details");
DataTable pay_dt=ds_pay .Tables ["details"];
con2.Close();
GridView2.DataSource = pay_dt;
GridView2.DataBind();
|
|
|
|
|
Hello
I have no experience with datagrid
But for DataGridView I'm sure about TWO think
1 : you must set the datasource to null before to reassign it
GridView2.DataSource = null;
GridView2.DataSource = pay_dt;
2 : this is not necessary :
GridView2.DataBind();
|
|
|
|
|
Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------
Syntax error (missing operator) in query expression 'DOCTOR NAME = 'ankit''.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'DOCTOR NAME = 'ankit''.
Source Error:
Line 175: OleDbCommand cmd4 = new OleDbCommand(query,con1);
Line 176: //cmd4.ExecuteNonQuery
Line 177: dr = cmd4.ExecuteReader();
Line 178: if (dr.Read())
Line 179: {
Source File: c:\Users\Ankit\Documents\Visual Studio 2005\WebSites\WebSite1\Default2.aspx.cs Line: 177
my code is
tring connection1 = ConfigurationManager.AppSettings["conn"];
OleDbConnection con1 = new OleDbConnection(connection1);
con1.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
OleDbDataReader dr;
string query="select COUNT(*) from appointment where DOCTOR NAME = '" + DropDownList1.SelectedItem + "' ";
OleDbCommand cmd4 = new OleDbCommand(query,con1);
//cmd4.ExecuteNonQuery
dr = cmd4.ExecuteReader();
if (dr.Read())
{
//if (Convert.ToInt16(dr[0]) != 4)
TextBox3.Text = "hello";
TextBox3.Text = dr[0].ToString();
}
|
|
|
|
|
Are you sure it should be 'DOCTOR NAME' with the space? As far as I know, SQL doesn't like having spaces in field names, or at least, not used in the way you have here.
Edit: Looking at your code below, this seems likely. Did you copy and paste this code snippet or copy it out by hand?
Also, try and avoid things like 'plz', it annoys people.
|
|
|
|
|
okk....i got it correct.the problem was with the field name itself.
|
|
|
|
|
You just asked this question, wait for a response or continue to post on that thread don't start a new one.
only two letters away from being an asset
|
|
|
|
|
Arguably, it is a different error. Same set of code though.
|
|
|
|
|
Hi i m developing windows application in C#.net,where i m using datagridview. i want to disply only some of column when the application get execute. right now im storing the column header text, width and displayindex in textfile.and at the time of execute i read the textfile and apply thos header text, width and displayindex to the datagridview
but not displaying in proper manner
plz help me..
thanks
|
|
|
|
|
Do you want to hide the columns, that you dont need ?
If yes :
Sample :
dataGridView1.Columns[1].Visible = false;
|
|
|
|