0

これは私のaspxページです....

    <asp:Panel ID="UpdatePanel1" runat="server" Visible="false" >   
           <rsweb:ReportViewer ID="ReportingForPrintingReportViewer" runat="server"
           Width="100%" Height="100%" Font-Names="Verdana" Font-Size="8pt"
           InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
           WaitMessageFont-Size="14pt">  
           <LocalReport ReportPath="Report.rdlc">
           <DataSources>
           <rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="DataSet1" />
           </DataSources>
           </LocalReport>
           </rsweb:ReportViewer>  
           <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
             SelectMethod="GetData" TypeName="DataSet1TableAdapters.tblTotalFeeTableAdapter">
           </asp:ObjectDataSource>
                 </asp:Panel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="150px"
           onclick="btnSubmit_Click" />
       <asp:Button ID="btnReset" runat="server" Text="Reset" Width="150px" />
       <asp:Button ID="btnCreateBill" runat="server" Text="CreateBill" Width="150px" 
           onclick="btnCreateBill_Click"/>


       <asp:PopupControlExtender ID="btnCreateBill_PopupControlExtender" OffsetX="-1100" OffsetY="115" 
           runat="server" DynamicServicePath="" Enabled="True" ExtenderControlID="" 
           TargetControlID="btnCreateBill" PopupControlID="UpdatePanel1">
       </asp:PopupControlExtender>

これは私のcsページです

 protected void btnCreateBill_Click(object sender, EventArgs e)
    {
        DisplayReport();
        UpdatePanel1.Visible = true;

    }
    private DataTable TotalInfoData()
    {
        try
        {
            //DataClassesDataContext db = null;
            //db = new DataClassesDataContext();
            //var s = from p in db.tblTotalFeess
            //        where p.Class == ClassDropDownList.SelectedItem.Value && p.StudentID == Convert.ToInt32(StudentNameDropDownList.SelectedValue)
            //        select p;

            //DataTable dt = new DataTable();
            //SQLHelper sqhlpr = new SQLHelper();
            //sqhlpr.SqlText = "select * from tblTotalFee where Class='" + ClassDropDownList.SelectedItem.Value + "'" + "and StudentID='" + StudentNameDropDownList.SelectedValue + "'";
            //DataTable dt = sqhlpr.getDataTable(false);
            //return dt;
            try
            {
                // Open Sql Connection  
                SqlConnection SqlCon = new SqlConnection(@"Data Source=PRATIKPC;Initial Catalog=dbbilling2.0;Integrated Security=True");
                SqlCon.Open();

                // Create a Command  
                SqlCommand SqlComm = new SqlCommand();
                SqlComm.Connection = SqlCon;
                SqlComm.CommandType = CommandType.Text;
                SqlComm.CommandText = "select * from tblTotalFee where Class='" + ClassDropDownList.SelectedItem.Value + "'" + "and StudentID='" + StudentNameDropDownList.SelectedValue + "'";

                // Create instance of Northwind DataSetXSD  
                DataSet1.tblTotalFeeDataTable dtbl = new DataSet1.tblTotalFeeDataTable();

                // Set a Data Commands  
                SqlDataAdapter SqlDa = new SqlDataAdapter(SqlComm);
                SqlDa.Fill(dtbl); // Fill Data in NorthwindDataSet Object.  

                return dtbl;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }  

        } 

        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
    private void DisplayReport()
    {
        try
        {
            // Clear the Data Source   
            ReportingForPrintingReportViewer.LocalReport.DataSources.Clear();

            // Set a DataSource to the report  

            // First Parameter - Report DataSet Name  
            // Second Parameter - DataSource Object i.e DataTable  
            ReportingForPrintingReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", TotalInfoData()));

            // OR Set Report Path  
            ReportingForPrintingReportViewer.LocalReport.ReportPath = HttpContext.Current.Server.MapPath("~/Report.rdlc");

            // Refresh and Display Report  
            ReportingForPrintingReportViewer.LocalReport.Refresh();

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

レポート ビューアーを生成するには、btnCreateBill を 2 回クリックする必要があります。なんで?また、ボタンを 1 回クリックするだけでレポート ビューアーを生成するにはどうすればよいでしょうか。

4

2 に答える 2

0

!ispostback の中で Get Data メソッド (Your Data Source load method) を呼び出していますか?

これを見て

protected void Page_Load(object sender, EventArgs e)
{    
    if (!Page.IsPostBack)
        {   
             GetData()// Your Data Source load method
        }
}
于 2013-04-20T07:35:12.700 に答える