我的页面目前看起来像这样:
<!-- Datasource -->
<asp:SqlDataSource ID="SqlDataSource_GetURL" runat="server" ConnectionString="<%$ ConnectionStrings:TEST_DEV1 %>" SelectCommand="TEST_GetReports" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="CustomerID" Type="String" />
<asp:Parameter DefaultValue="0" Name="UserId" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<!-- Dropdown List -->
Company: <asp:DropDownList ID="ddlCompanyList"
runat="server" OnSelectedIndexChanged="ddlCompanyList_SelectedIndexChanged"
AutoPostBack="true" DataSourceID="SqlDataSource_GetURL"
DataValueField="RSReportLinkID" DataTextField="ReportName" CssClass="select">
</asp:DropDownList>
<!-- Report Viewer -->
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Width="930px" Height="1000" Font-Size="8pt" ProcessingMode="Remote" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<ServerReport ReportPath="/Systems/Test/Report 1" ReportServerUrl="http://test/ReportServer" />
</rsweb:ReportViewer>
背后的代码是:
protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{
//TODO: change to SP
string strConnectionString = ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString;
string strCustomerID = CommonCode.GetCurrentCustomerID();
string strUserID = CommonCode.GetCurrentUserID().ToString();
using (SqlConnection connection = new SqlConnection(strConnectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("TEST_GetReportSettingsForReport", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@CustomerID", strCustomerID);
command.Parameters.AddWithValue("@UserId", strUserID);
command.Parameters.AddWithValue("@RSReportLinkID", "5CCD639D-E930-4896-AE36-323EC3495D24");
;
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Response.Write(reader.GetValue(3));
}
}
else
{
/* Console.WriteLine("No rows found.");*/
}
reader.Close();
connection.Close();
}
}
目前@RSReportLinkID被硬编码为5CCD639D-E930-4896-AE36-323EC3495D24,因此当通过下拉列表选择报告时,ddlCompanyList_SelectedIndexChanged将完成它的魔术并从表的第四列返回ReportPath,这要归功于这一行:
Response.Write(reader.GetValue(3));
我的问题是,如何将ReportLinkID传递给@RSReportLinkID而不是硬编码?我的下拉列表中的选项是从存储过程中提取的,该存储过程从表中获取报告列表。每个报告在第一列中也有一个ReportLinkID,所以我希望只做一些事情......如果从下拉列表中选择一个报告,这将是一个SelectedIndexChange,我的表中的第一列被抓取(这将是ReportLinkID),然后将其传递给我的代码并存储在@RSReportLinkID。
感谢您的帮助或信息!我觉得这很简单,涉及使用对象发送器和EventArgs e,但是我无法绕过它。
答案 0 :(得分:1)
我认为您需要将RSReportLinkID存储为下拉列表的值。这样在ddlCompanyList_SelectedIndexChanged方法中你就可以像这样访问它:
protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
string RSReportLinkID = ddl.SelectedValue;
}