2

我的页面目前看起来像这样:

<!-- 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 的使用,但是我很难理解它。

4

1 回答 1

1

我认为您需要将 RSReportLinkID 存储为下拉列表的值。这样,在 ddlCompanyList_SelectedIndexChanged 方法中,您将能够像这样访问它:

protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddl = sender as DropDownList;
    string RSReportLinkID = ddl.SelectedValue;
}
于 2013-10-08T09:30:19.587 回答