Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CheckBox Always Print Current Date

Posted on 2009-05-18
7
Medium Priority
?
511 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
  • 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 1500 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

824 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