Solved

CheckBox Always Print Current Date

Posted on 2009-05-18
7
485 Views
Last Modified: 2013-11-26
Dear Experts-Exchange,

I have a textbox id=textbox1 that searches information number and checkbox id=CheckBox1 for Always Print Current Date and the button id=BtnPrint Go  (see the attachament)

In Sql Database I have this  :  

InfoNumber                                 DateInfo

12345                                           1/19/2009
12345                                           5/18/2009   (this is the current date)
12345                                           4/22/2009


I would like to know after typing the information number in the text box 12345 and checked the box for printing the current date from the information number, it will printing the information.  How would I do this?

See the below
Protected Sub BtnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
 
If Textbox1.Text = "" Then
            LblError.Text = "Please: Enter Information Number value!"
            Textbox1.Focus()
        Else
            LblError.Text = ""
        End If
 
DataFill()
CheckedBox1()
 
End Sub
 
Private Sub DataFill()
 
Dim da As SqlDataAdapter
        Dim ds As Data.DataSet
        Dim strSQL As String
        Dim strCnn As String
 
Try
 
strSQL = "SELECT InfoNum, " & _
"CONVERT (varchar(2), DATEPART(mm, DateInfo, GetDate())) + '/' + CONVERT (varchar(2), DATEPART(dd, DateInfo, GetDate())) + '/' + CONVERT (varchar(4), DATEPART(yyyy, DateInfo, GetDate())) AS [DateInfo]  FROM InfoData  &
WHERE InfoNum =  & Trim(TextBox1.text) &  and CurrentDate =                   
 
strCnn = System.Configuration.ConfigurationManager.AppSettings("ABCStringConn)
 
da = New SqlDataAdapter(strSQL, strCnn)
            ds = New Data.DataSet()
            da.Fill(ds, "infodata")
            Session("DataView") = ds.Tables("InfoData").DefaultView()
End Try
    End Sub
 
 
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles CheckBox1CheckedChanged
 
If CheckBox1.Checked = True Then
 
Print&&. (what is the SQL Statement/VB.NET code for printing the checked current date 5/19/2009 from SQL database)
 
End if
End sub
 
Thanks

Open in new window

Search.jpg
0
Comment
Question by:slb2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:M3mph15
ID: 24417751
Hi,

What you could do is create a new page that you open in a new window, pass those parameters to show in a label and then print it. This can all be done using javascript.

I'm not at a computer to test any code so i'll post some when i can but basically you will need a javascript function that grabs the values of the textbox and the checkbox and sends it to the new page in the quersytring.

e.g. PrintPage.aspx?txt=<textbox value>&chk=<Checkbox value>. So then the new page grabs those values and displays them in a label.

Then you can use window.print() in a javascript function on the page load(in the new page) to bring up the print dialog.

This will allow the user to select what printer they want.

Will post code for the first bit later on

-M3mph15


0
 

Author Comment

by:slb2008
ID: 24418089
Hi M3mhp15,
Thanks for your quick response.
I'll be waiting for the code.
Thanks  slb2008
 
0
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 24420118
Hi slb2008, Here is the code:

For this example i'll use the names Home.aspx and PrintPage.aspx for the webpages.

So in the <head> section of Home.aspx insert the following:

function PrintDate()
        {
            var txt =  document.getElementById('<%= <name of textbox>.ClientID %>').innerHTML  ;
            var chk = document.getElementById('<%= <name of checkbox>.ClientID %>').checked;
            var obj_calwindow = window.open(
                    'PrintPage.aspx?txt=' + txt + '&chk=' + chk, 'Print', 'width=600,height='+'650'+
                    ',status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes'
                    );
        }
The above function will grab the data from the textbox and checkbox and send the data to another page (which opens in a seperate window) in the querystring.

Now to make the button call the javascript function:
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintDate()" />

Now we have to retrieve the data from the querystring and then print the page. So make sure on PrintPage.aspx that there are 2 labels. After a few test prints you can move the labels to suit your formatting.
So in the code behind of PrintPage.aspx within the PageLoad event:
String txt = Request.QueryString("txt")
String chk = Request.QueryString("chk")
Label1.Text = txt
If chk == "True" Then 'Im not 100% sure what the value of chk will be.
     Label2.Text = Date.Today().ToString()
End If

And then in the <head> section of PrintPage.aspx:
    <script type="text/javascript">
        var p = window.print();
        window.close;
    </script>

So when that is all implemented on the click of the button it will open up another window and automatically bring up the print dialog and once it is printed it will close the window.

HTH
-M3mph15

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:slb2008
ID: 24424126

Hi M3mph15,
I received the code  and I am going to try it.
It's correct the value of chk will be true or false.
I will let you know later.
If you please, I inserted a new question titled "GridView with buttons Print, View and Add".  Maybe you could view my new question.
Thanks, slb2008
0
 

Author Comment

by:slb2008
ID: 24424127
Hi M3mph15,
I received the code  and I am going to try it.
It's correct the value of chk will be true or false.
I will let you know later.
If you please, I publish a new question titled "GridView with buttons Print, View and Add".  Maybe you could view my new question.
Thanks, slb2008
0
 
LVL 6

Expert Comment

by:M3mph15
ID: 24470346
Hey sbl2008,

Any feedback on wether my coding workedor not?

-M3mph15
0
 

Author Comment

by:slb2008
ID: 24478984
Hi M3mph15,
I am sorry I didn't answer you soon.  Your code worked well, but I did different way, which is working now.  Thanks for your help.
I will end here to give 500 points acepting as solution.
Thanks
 
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question