问题描述
我遵循了
这是 Incomplete_Prodcut.aspx 文件
<%@页面语言="C#" AutoEventWireup ="true" CodeBehind ="Incomplete_Prodcut.aspx.cs" Inherits ="albaraka.Report.Incomplete_Prodcut"%><%@注册Assembly ="Microsoft.ReportViewer.WebForms,版本= 12.0.0.0,文化=中性,PublicKeyToken = 89845dcd8080cc91"命名空间="Microsoft.Reporting.WebForms" TagPrefix ="rsweb"%><!DOCTYPE html>< html xmlns ="http://www.w3.org/1999/xhtml">< head runat ="server">< title></title></head><身体>< form id ="form1" runat ="server">< div style ="width:1116px">< asp:ScriptManager ID ="ScriptManager1" runat ="server"></asp:ScriptManager>< br/>类型:< asp:TextBox ID =类型" runat =服务器" Width ="64px"></asp:TextBox>& nbsp;类别:< asp:TextBox ID ="category" runat ="server" Width ="78px"></asp:TextBox>& nbsp;国家/地区:< asp:TextBox ID ="country" runat ="server" Width ="85px"></asp:TextBox>& nbsp;辅助:< asp:TextBox ID ="subsidary" runat ="server" Width ="72px"></asp:TextBox>& nbsp;日期:< asp:TextBox ID =日期" runat =服务器" Width ="100px"></asp:TextBox>& 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 文件
受保护的空白Page_Load(对象发送者,EventArgs e){}受保护的无效btnShow_Click(对象发件人,EventArgs e){ShowReport();}私人无效ShowReport(){//重启ReportViewer1.Reset();//数据源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);//小路ReportViewer1.LocalReport.ReportPath =〜/Report/Incomplete_Product.rdlc";//参数ReportParameter [] rptParams = new ReportParameter [] {新的ReportParameter("type",type.Text),新的ReportParameter("category",category.Text),新的ReportParameter("country",country.Text),新的ReportParameter("subsidary",subsidary.Text),新的ReportParameter("date",date.Text),};ReportViewer1.LocalReport.SetParameters(rptParams);//刷新ReportViewer1.LocalReport.Refresh();}私有ALBARAKA_Incomplete_Product_DataSet GetData(字符串类型,字符串类别,字符串国家/地区,字符串辅助,DateTime?日期){ALBARAKA_Incomplete_Product_DataSet dt =新ALBARAKA_Incomplete_Product_DataSet();字符串connStr = System.Configuration.ConfigurationManager.ConnectionStrings ["AB_ReportEntities"].ConnectionString;使用(SqlConnection cn = new SqlConnection(connStr)){SqlCommand cmd =新的SqlCommand("FindIncomplete_Products",cn);cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.Add("@ type",SqlDbType.NVarChar).Value =类型;cmd.Parameters.Add("@ category",SqlDbType.NVarChar).Value =类别;cmd.Parameters.Add("@ country",SqlDbType.NVarChar).Value =国家/地区;cmd.Parameters.Add("@ subsidary",SqlDbType.NVarChar).Value =子级;cmd.Parameters.Add("@ date",SqlDbType.DateTime).Value =日期;SqlDataAdapter adp =新的SqlDataAdapter(cmd);adp.Fill(dt);}返回dt}
我在上面形式的OnClick事件中插入了调试点,但是一旦在调试模式下运行此应用程序并单击"btnShow"按钮,此应用程序就不会指向此调试点.我的方法怎么了?
您尚未将事件处理程序附加到按钮上,请添加以下内容:-
< asp:Button ID ="btnShow" runat ="server" Text ="Button" Width ="56px"OnClick ="btnShow_Click"/>
或者,您也可以像这样通过编程方式附加事件:-
受保护的空白Page_Load(对象发送者,EventArgs e){btnShow.Click + = btnShow_Click;}
I followed this tutorial to create following ASP.NET web form to send parameters to a stored procedure and show the results using Microsoft Report.
this is Incomplete_Prodcut.aspx file
<%@ 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>
Category:
<asp:TextBox ID="category" runat="server" Width="78px"></asp:TextBox>
Country:
<asp:TextBox ID="country" runat="server" Width="85px"></asp:TextBox>
Subsidary:
<asp:TextBox ID="subsidary" runat="server" Width="72px"></asp:TextBox>
Date:
<asp:TextBox ID="date" runat="server" Width="100px"></asp:TextBox>
<asp:Button ID="btnShow" runat="server" Text="Button" Width="56px" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="397px" Width="951px" style="margin-top: 17px; margin-right: 0px;"></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
this is Incomplete_Prodcut.aspx.cs file
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;
}
I inserted debug point inside the OnClick event of above form, but Once run this application in debug mode and click "btnShow" button this application does not point to this debug point. whats wrong with my approach ?
You have not attached the event handler to the button, add one:-
<asp:Button ID="btnShow" runat="server" Text="Button" Width="56px"
OnClick="btnShow_Click" />
Alternatively, you can also attach the event programmatically like this:-
protected void Page_Load(object sender, EventArgs e)
{
btnShow.Click += btnShow_Click;
}
这篇关于按钮OnClick事件在ASP.NET Web窗体应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!