2012-08-14 91 views
1

我有一個現有的SQL數據庫和一個ASP.NET應用程序。我的應用程序有兩個現有GridViews和登錄功能。我還有一個現有的Crystal Report,旨在從我的SQL數據庫中自動創建收據。這由用戶填寫3個特定參數完成,其餘數據(與這些參數並行)將自動填寫水晶報告。如何將參數傳遞給我的GridView中的Crystal報表?

我想在我的GridView中創建一個打印按鈕來自動填寫Crystal Report中的3個參數。這是試圖讓我的應用程序更加用戶友好。簡而言之,用戶將在GridView的新列中按下打印按鈕,3個參數將被自動拾取並填充到Crystal Report中。

我的參數是:「EmpID」,「KeyControl」和「ControlNumber」。我的水晶報表標籤是「x.rpt」

這裏是我的GridView標記:

<asp:GridView ID="gridKeyAndBuildingInformation" runat="server" CssClass="style3" 
       AllowSorting ="True" 
       AutoGenerateColumns ="False" 
       AllowPaging="True" 
       DataKeyNames="KeyRefId" 
       OnRowCancelingEdit="gridKeyAndBuildingInformation_RowCancelingEdit" 
       onPageIndexChanging="gridKeyAndBuildingInformation_PageIndexChanging" 
       OnRowDataBound="gridKeyAndBuildingInformation_RowDataBound" 
       OnRowEditing="gridKeyAndBuildingInformation_RowEditing" 
       OnRowUpdating="gridKeyAndBuildingInformation_RowUpdating" 
       OnRowCommand="gridKeyAndBuildingInformation_RowCommand" 
       ShowFooter="True" 
       OnRowDeleting="gridKeyAndBuildingInformation_RowDeleting"          
       AlternatingRowStyle-BackColor="#EFEFEF" 
       EditRowStyle-VerticalAlign="Top" 
       HeaderStyle-BackColor="#77b218" 
       OnSorting="gridKeyAndBuildingInformation_Sorting" 
       BackColor="#CCCCCC" 
       BorderColor="#999999" 
       BorderStyle="Solid" 
       BorderWidth="3px" 
       CellPadding="4" 
       EnableModelValidation="True" 
       ForeColor="Black" 
       CellSpacing="2"> 
<Columns> 

<asp:TemplateField HeaderText ="EmpID" HeaderStyle-CssClass="HeaderText" sortexpression="EmpID"> 
    <ItemTemplate>      
    <asp:Label ID="lblEmpID" runat="server" Text='<%# Eval("EmpID") %>'></asp:Label> 
</ItemTemplate> 
<EditItemTemplate> 
    <asp:TextBox ID="txtEmpID" runat="server" Text='<%# Eval("EmpID") %>' Width="50px"></asp:TextBox> 
</EditItemTemplate> 
<FooterTemplate> 
    <asp:TextBox ID="txtNewEmpID" runat="server" Width="50px"></asp:TextBox> 
</FooterTemplate> 
<HeaderStyle CssClass="HeaderText" /> 
</asp:TemplateField> 

<asp:TemplateField HeaderText ="ControlNumber" HeaderStyle-CssClass="HeaderText" sortexpression="ControlNumber"> 
<ItemTemplate>      
    <asp:Label ID="lblControlNumber" runat="server" Text='<%# Eval("ControlNumber") %>'></asp:Label> 
</ItemTemplate> 
<EditItemTemplate> 
    <asp:TextBox ID="txtControlNumber" runat="server" Text='<%# Eval("ControlNumber") %>' Width="50px"></asp:TextBox> 
</EditItemTemplate> 
<FooterTemplate> 
    <asp:TextBox ID="txtNewControlNumber" runat="server" Width="50px"></asp:TextBox> 
</FooterTemplate> 
<HeaderStyle CssClass="HeaderText" /> 
</asp:TemplateField> 

<asp:TemplateField HeaderText ="KeyNumber" HeaderStyle-CssClass="HeaderText" sortexpression="KeyNumber"> 
<ItemTemplate>      
    <asp:Label ID="lblKeyNumber" runat="server" Text='<%# Eval("KeyNumber") %>'></asp:Label> 
</ItemTemplate> 
<EditItemTemplate> 
    <asp:TextBox ID="txtKeyNumber" runat="server" Text='<%# Eval("KeyNumber") %>' Width="50px"></asp:TextBox> 
</EditItemTemplate> 
<FooterTemplate> 
    <asp:TextBox ID="txtNewKeyNumber" runat="server" Width="50px"></asp:TextBox> 
</FooterTemplate> 
<HeaderStyle CssClass="HeaderText" /> 
</asp:TemplateField> 

<asp:TemplateField HeaderText="Edit" ShowHeader="False"> 
<EditItemTemplate> 
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
</EditItemTemplate> 
<FooterTemplate> 
    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton> 
</FooterTemplate> 
<ItemTemplate> 
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
</ItemTemplate> 
</asp:TemplateField> 

<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" /> 
<asp:ButtonField HeaderText="Print" ShowHeader="True" Text="Print" /> 

</Columns> 

<EditRowStyle VerticalAlign="Top"></EditRowStyle> 
<FooterStyle BackColor="#CCCCCC" /> 
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White"></HeaderStyle> 
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /> 
<RowStyle BackColor="White" /> 
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> 
</asp:GridView> 

回答

1

你可以處理RowCommand事件,當你點擊在你ButtonField欄刪除按鈕,這將觸發。如果,

OnRowCommand="gridKeyAndBuildingInformation_RowCommand" 

,然後在後面的代碼,你需要這樣的事情(這是C#:添加到您的GridView聲明標記結束(在「CellSpacing="2"」但在此之前的「>」)需要VB.NET讓我知道 - 這個問題沒有標記與服務器端語言):

protected void gridKeyAndBuildingInformation_RowCommand(Object sender, GridViewCommandEventArgs e) 
{ 
    // Get your ID for the row you're on 
    int ID = Convert.ToInt32(e.CommandArgument); 

    // Get the row the button was clicked in 
    GridViewRow row = gridKeyAndBuildingInformation.Rows[ID]; 

    // Get the values you need from that row 
    int EmpID = row.Cells[0]; 
    int ControlNumber = row.Cells[1]; 
    int KeyNumber = row.Cells[2]; 

    // Use those numbers to make your call to the Crystal Report 
    // I don't know what this part would look like. 
} 

你可以閱讀更多關於RowCommand事件的MSDN:GridView.RowCommand Event

+0

它在C#中,我實際上發現這個:http://stackoverflow.com/q uestions/5511682/passing-parameters-to-crystal-report-from-webforms – 2012-08-15 14:30:47

+0

@ user1574656這樣其他文章解決了你的問題? – jadarnel27 2012-08-15 15:06:11

+0

還沒有,但iam試圖找出它。如果有人有這方面的經驗,任何幫助仍然值得讚賞。 – 2012-08-15 15:08:31

相關問題