2015-09-17 4 views
1

Я выполнил this tutorial, чтобы создать следующую веб-форму ASP.NET для отправки параметров хранимой процедуре и отображения результатов с помощью Microsoft Report.Кнопка Событие OnClick, не работающее в веб-форме ASP.NET в приложении MVC 5

enter image description here

это Incomplete_Prodcut.aspx файл

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Incomplete_Prodcut.aspx.cs" Inherits="albaraka.Report.Incomplete_Prodcut" %> 

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div style="width: 1116px"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
     <br /> 
     Type: 
     <asp:TextBox ID="type" runat="server" Width="64px"></asp:TextBox> 
&nbsp;Category: 
     <asp:TextBox ID="category" runat="server" Width="78px"></asp:TextBox> 
&nbsp;Country: 
     <asp:TextBox ID="country" runat="server" Width="85px"></asp:TextBox> 
&nbsp;Subsidary: 
     <asp:TextBox ID="subsidary" runat="server" Width="72px"></asp:TextBox> 
&nbsp; Date: 
     <asp:TextBox ID="date" runat="server" Width="100px"></asp:TextBox> 
&nbsp;&nbsp;&nbsp;&nbsp; 
     <asp:Button ID="btnShow" runat="server" Text="Button" Width="56px" /> 
&nbsp;<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="397px" Width="951px" style="margin-top: 17px; margin-right: 0px;"></rsweb:ReportViewer> 
    </div> 
    </form> 
</body> 
</html> 

это Incomplete_Prodcut.aspx.cs файл

protected void Page_Load(object sender, EventArgs e) 
{ 

} 

protected void btnShow_Click(object Sender, EventArgs e) 
{ 
    ShowReport(); 
} 

private void ShowReport() 
{ 
    //Reset 
    ReportViewer1.Reset(); 

    //DataSource 
    ALBARAKA_Incomplete_Product_DataSet dt = GetData(type.Text, category.Text,subsidary.Text,country.Text, DateTime.Parse(date.Text)); 
    ReportDataSource rds = new ReportDataSource("Incomplete_Product_DataSet", dt); 

    ReportViewer1.LocalReport.DataSources.Add(rds); 

    //Path 
    ReportViewer1.LocalReport.ReportPath = "~/Report/Incomplete_Product.rdlc"; 

    //Paramaeters 
    ReportParameter[] rptParams = new ReportParameter[] { 
     new ReportParameter("type",type.Text), 
     new ReportParameter("category", category.Text), 
     new ReportParameter("country",country.Text), 
     new ReportParameter("subsidary",subsidary.Text), 
     new ReportParameter("date",date.Text), 
    }; 
    ReportViewer1.LocalReport.SetParameters(rptParams); 

    //Refersh 
    ReportViewer1.LocalReport.Refresh(); 

} 

private ALBARAKA_Incomplete_Product_DataSet GetData(string type, string category, string country, string subsidary, DateTime? date) 
{ 

    ALBARAKA_Incomplete_Product_DataSet dt = new ALBARAKA_Incomplete_Product_DataSet(); 
    string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["AB_ReportEntities"].ConnectionString; 
    using (SqlConnection cn = new SqlConnection(connStr)) 
    { 

     SqlCommand cmd = new SqlCommand("FindIncomplete_Products", cn); 
     cmd.CommandType = CommandType.StoredProcedure; 
     cmd.Parameters.Add("@type", SqlDbType.NVarChar).Value = type; 
     cmd.Parameters.Add("@category", SqlDbType.NVarChar).Value = category; 
     cmd.Parameters.Add("@country", SqlDbType.NVarChar).Value = country; 
     cmd.Parameters.Add("@subsidary", SqlDbType.NVarChar).Value = subsidary; 
     cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = date; 

     SqlDataAdapter adp = new SqlDataAdapter(cmd); 

     adp.Fill(dt); 
    } 

    return dt; 
} 

Я вставил отладки точку внутри события OnClick из выше формы, но после запуска этого приложения в d ebug и нажмите кнопку «btnShow», это приложение не указывает на эту точку отладки. Что не так с моим подходом?

enter image description here

ответ

1

Вы не прикрепил обработчик события для кнопки, добавьте один: -

<asp:Button ID="btnShow" runat="server" Text="Button" Width="56px" 
      OnClick="btnShow_Click" /> 

В качестве альтернативы, вы можете также прикрепить событие программно, как это: -

protected void Page_Load(object sender, EventArgs e) 
{ 
    btnShow.Click += btnShow_Click; 
} 
+1

благодаря теперь работе – kez