My page currently looks like this:
<!-- 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>
The code behind it is:
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();
}
}
Currently @RSReportLinkID is hard coded to be 5CCD639D-E930-4896-AE36-323EC3495D24, so when a report is selected via the drop down, ddlCompanyList_SelectedIndexChanged will do it's magic and return the ReportPath from the fourth column of my table thanks to this line:
Response.Write(reader.GetValue(3));
My question however is, how can I pass a ReportLinkID to @RSReportLinkID instead of hard coding one? The options in my dropdown list are being fed through from a stored procedure that grabs a list of reports from a table. Each report also has a ReportLinkID in the first column, so I am hoping just to do something such as... When a report is selected from the drop down which would be a SelectedIndexChange, the first column from my table is grabbed (which will be the ReportLinkID) and this is then passed onto my code and stored in @RSReportLinkID.
Thanks for any help or information! I have a feeling that this is something very simple that will involve the use of object sender and EventArgs e, however I am having trouble wrapping my head around it.
I think you need to store RSReportLinkID as the value of the dropdownlist. That way in the ddlCompanyList_SelectedIndexChanged method you will be able to access it like this:
protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
string RSReportLinkID = ddl.SelectedValue;
}