DTaylorAtWork
Technical User
I've been tasked with creating pages to allow users to create edit and display their own reports. I have the generation functioning properly, if not efficiently but it's when I go to the running of the report that things get problematic.
Because the reports are dynamic they can have any number of parameters involved so I need to generate controls (for now just text boxes) to allow the users to give the parameters values.
The controls are generated properly and no errors are thrown during execution but if the report has any parameters then no results are shown. The grid view is populated properly if there are no parameters in the select query.
Here is the code for generating the controls.
And the BuildDataSource function
Can anyone give me any hints on what to try next?
Because the reports are dynamic they can have any number of parameters involved so I need to generate controls (for now just text boxes) to allow the users to give the parameters values.
The controls are generated properly and no errors are thrown during execution but if the report has any parameters then no results are shown. The grid view is populated properly if there are no parameters in the select query.
Here is the code for generating the controls.
Code:
protected override void OnInit(EventArgs e)
{
currReport = new Report(Convert.ToInt32(Request.QueryString["ReportID"]));
((Label)Master.FindControl("lblMain")).Text = "Running Report: " + currReport.Name;
int varIndex = 0;
while (varIndex < currReport.Command.LastIndexOf("@") && currReport.Command.IndexOf("@") > -1)
{
varIndex = currReport.Command.IndexOf("@");
string variable = currReport.Command.Substring(varIndex,
currReport.Command.IndexOf(" ", varIndex) - varIndex);
Form.FindControl("ContentPlaceHolder1").Controls.AddAt(0, new Label());
Form.FindControl("ContentPlaceHolder1").Controls[0].ID = "lbl" + variable.Substring(1);
((Label)Form.FindControl("ContentPlaceHolder1").Controls[0]).Text = variable;
Form.FindControl("ContentPlaceHolder1").Controls.AddAt(1, new TextBox());
Form.FindControl("ContentPlaceHolder1").Controls[1].ID = "txt" + variable.Substring(1);
}
Form.FindControl("ContentPlaceHolder1").Controls.Add(currReport.BuildDataSource("sqldsResults"));
GridView gvResults = new GridView();
Form.FindControl("ContentPlaceHolder1").Controls.Add(gvResults);
gvResults.ID = "gvResults";
gvResults.AutoGenerateColumns = true;
gvResults.DataSourceID = "sqldsResults";
gvResults.EnableViewState = true;
}
And the BuildDataSource function
Code:
public SqlDataSource BuildDataSource(string id)
{
sqldsResults = new SqlDataSource(conn.ConnectionString, SelectCommand);
int varIndex = 0;
while (Command.IndexOf("@") > -1 && varIndex < Command.LastIndexOf("@"))
{
varIndex = Command.IndexOf("@");
string variable = Command.Substring(varIndex + 1,
Command.IndexOf(" ", varIndex) - (varIndex + 1));
ControlParameter param = new ControlParameter(variable, "txt" + variable);
sqldsResults.SelectParameters.Add(param);
}
sqldsResults.ID = id;
return sqldsResults;
}
Can anyone give me any hints on what to try next?