現在、私のページは次のようになっています。
<!-- 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 は魔法のように機能し、次の行のおかげでテーブルの 4 列目から ReportPath を返します。
Response.Write(reader.GetValue(3));
ただし、私の質問は、ReportLinkID をハードコーディングする代わりに @RSReportLinkID に渡すにはどうすればよいですか? ドロップダウン リストのオプションは、テーブルからレポートのリストを取得するストアド プロシージャからフィードされています。各レポートには最初の列にも ReportLinkID があるため、次のようなことをしたいと思っています...レポートがドロップダウンから選択され、SelectedIndexChange になると、テーブルの最初の列が取得されます (これはこれはコードに渡され、@RSReportLinkID に保存されます。
助けや情報をありがとう!これは、オブジェクト送信者と EventArgs e の使用を伴う非常に単純なものであると感じていますが、頭を悩ませています。