如何从网格视图选择按钮打印收据。是否可能? [英] How to print a receipt from grid view select button.Is it possible?

查看:60
本文介绍了如何从网格视图选择按钮打印收据。是否可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   asp:GridView     ID   =  GridView1     runat   =  server    AllowPaging   =  True    

AllowSorting = True AutoGenerateColumns = False BackColor = #DEBA84

BorderColor = #DEBA84 BorderStyle = BorderWidth = 1px CellPadding = 3

CellSpacing = 2 DataSourceID = SqlDataSource1 >
< >
< asp:BoundField DataField = pno HeaderText = PatientNo

SortExpression = pno / >
< asp:BoundField DataField = patient_name HeaderText = PatientName

< span class =code-attribute> SortExpression = patient_name / >
< asp:BoundField DataField = 性别 HeaderText = 性别

SortExpression = 性别 / >
< asp:BoundField DataField = age HeaderText = 年龄 SortExpression = age / >
< asp:BoundField DataField = patient_uery HeaderText = PatientQuery

SortExpression = patient_query / >
< asp:BoundField DataField = doctorname HeaderText = 医生

< span class =code-attribute> SortExpression = doctorname / >
< asp:BoundField DataField = dept HeaderText = dept SortExpression = Dept / >
< asp:BoundField DataField = email_id HeaderText = 电子邮件

SortExpression = email_id / >
< asp:TemplateField HeaderText = 选择 >
< itemtemplate >
< asp:按钮 ID = btn_select runat = server Com mandName = 选择 CommandArgument =' <% #Eval( pno)%>' 文字 = 选择 / >
< / itemtemplate >

< asp:TemplateField HeaderText = 删除 >
< itemtemplate >
< asp:按钮 ID = btn_delete runat = server CommandName = delete CommandArgument =' <% #Eval( pno)%>' 文本 = 删除 / >
< / itemtemplate > ;

< / columns >
< 页脚 style backcolor = #F7DFB5 forecolor = < span class =code-keyword>#8C4510 / >
< HeaderStyle BackColor = #A55129 Font-Bold = True ForeColor = 白色 / >
< pager style forecolor = #8C4510 horizo​​ntalalign = 中心 / >
< row style backcolor = #FFF7E7 forecolor = #8C4510 / >
< span class =code-keyword>< SelectedRowStyle BackColor = #738A9C 字体粗体 = True ForeColor = 白色 / >
< sortedascendingcell style backcolor = #FFF1D4 / >
< sortedascendingheader style backcolor = #B95C30 / >
< sorteddescendingcell style backcolor = #F1E5CE / >
< sorteddescendingheader style backcolor = #93451F / >

解决方案

是的它有效,在选定的更改和更改中携带值并调用打印方法



例如



http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanging%28v=vs.110% 29.aspx


嘿伙计,



您可以通过两种方式完成此操作:在Excel中下载Grid,然后按Ctrl + P进行打印,或者您可以直接打印。



我在这里创建了一篇文章:



http://www.c-sharpcorner.com/UploadFile/cd7c2e/export-sql-data-to-excel-using-Asp -Net / [ ^ ]



源代码可在文章的顶部找到。


< blockquote>因为你已经使用 TemplateField 来选择Button,所以你必须在 GridView.RowCommand Event [ ^ ]。

  protected   void  ContactsGridView_RowCommand( Object  sender,GridViewCommandEventArgs e)
{
// 如果在GridView控件中使用了多个按钮,请使用
// CommandName属性,用于确定单击了哪个按钮。
if (e.CommandName == select
{
// 这里写下您的打印逻辑。
}
}



如需打印,请参阅 - 如何在ASP.NET 2.0中打印 [ ^ ]。


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 

        AllowSorting="True" AutoGenerateColumns="False" BackColor="#DEBA84" 

        BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" 

        CellSpacing="2" DataSourceID="SqlDataSource1">
        <columns>
        <asp:BoundField DataField="pno" HeaderText="PatientNo" 

                SortExpression="pno" />
            <asp:BoundField DataField="patient_name" HeaderText="PatientName" 

                SortExpression="patient_name" />
            <asp:BoundField DataField="gender" HeaderText="Gender" 

                SortExpression="gender" />
            <asp:BoundField DataField="age" HeaderText="Age" SortExpression="age" />
            <asp:BoundField DataField="patient_uery" HeaderText="PatientQuery" 

                SortExpression="patient_query" />
            <asp:BoundField DataField="doctorname" HeaderText="Doctor" 

                SortExpression="doctorname" />
            <asp:BoundField DataField="dept" HeaderText="dept" SortExpression="Dept" />
            <asp:BoundField DataField="email_id" HeaderText="Email" 

                SortExpression="email_id" />
         <asp:TemplateField HeaderText="Select">
                  <itemtemplate>
                  <asp:Button ID="btn_select" runat="server" CommandName ="select" CommandArgument='<%# Eval("pno") %>' Text= "Select" />
                  </itemtemplate>
                  
                   <asp:TemplateField HeaderText="Delete">
                  <itemtemplate>
                  <asp:Button ID="btn_delete" runat="server" CommandName ="delete" CommandArgument='<%# Eval("pno") %>' Text= "Delete" />
                  </itemtemplate>
                  
                  </columns>
        <footerstyle backcolor="#F7DFB5" forecolor="#8C4510" />
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        <pagerstyle forecolor="#8C4510" horizontalalign="Center" />
        <rowstyle backcolor="#FFF7E7" forecolor="#8C4510" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        <sortedascendingcellstyle backcolor="#FFF1D4" />
        <sortedascendingheaderstyle backcolor="#B95C30" />
        <sorteddescendingcellstyle backcolor="#F1E5CE" />
        <sorteddescendingheaderstyle backcolor="#93451F" />

解决方案

yes it works, on selected changed and changing carry the value and call print method

eg

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanging%28v=vs.110%29.aspx


Hey Buddy,

You can do it in two ways either download the Grid in Excel and then take the print by "Ctrl+P" or you can directly take printout.

Here I had created an article on the same :

http://www.c-sharpcorner.com/UploadFile/cd7c2e/export-sql-data-to-excel-using-Asp-Net/[^]

Source Code is available at the top of the Article.


As you have used TemplateField for the Select Button, so you have to handle it inside the GridView.RowCommand Event[^].

protected void ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="select")
    {
        // Here write your print logic.
    }
}


For printing, refer - How to Print in ASP.NET 2.0[^].


这篇关于如何从网格视图选择按钮打印收据。是否可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆