Error: Must declare the scalar variable 5 - sqldatasource

I'm battling to make the transition from Classic ASP to ASP.NET. I have the code below that works if I hard code the start date and end date but gives the error: System.Data.SqlClient.SqlException: Must declare the scalar variable "#SDate" when I use parameters. There are may references to this error when I search for it, but I just can't find one that helps me. The page is designed to display two text boxes for the user to enter the start and end date for the search and then click the button to have the data exported to Excel.
<%# Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" EnableViewStateMac="false"%>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<%# Import Namespace="System.Web.UI.WebControls" %>
<html>
<head>
<title>Export results to Excel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="C#" runat="server">
protected void btnExportToExcel_Click(object sender, EventArgs e) {
ExportToExcel();
}
//Export to Excel from a GridView
protected void ExportToExcel() {
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=MyFiles.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
gvData.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control) {
}
</script>
</head>
<body>
Export results to excel
</body>
<form id="form1" runat="server">
<div>
<h1>
My Files</h1>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 12%">
<tr>
<td>
Start date</td>
<td>
<asp:TextBox ID="StartDate" runat="server" Width="200px" Text="2000/01/01"></asp:TextBox>
</td>
</tr>
<tr>
<td>
End date</td>
<td>
<asp:TextBox ID="EndDate" runat="server" Width="200px" Text="2012/11/01"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel" onclick="btnExportToExcel_Click" />
</td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:KpraxConn %>"
SelectCommand="SELECT Results.IDNumber, [FirstName], [LastName], [DOB], [Gender] FROM [Results] LEFT JOIN Login ON (Results.IDNumber=Login.IDNumber) where ([LogDate]>=#SDate and [LogDate]<=#EDate) ORDER BY [LastName]">
<asp:SelectParameters>
<asp:FormParameter FormField="StartDate" Name="SDate" DefaultValue="2000/01/01" />
<asp:FormParameter FormField="EndDate" Name="EDate" DefaultValue="2012/11/04" />
</asp:SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False" DataKeyNames="IDNumber"
DataSourceID="SqlDataSource" PageSize="5">
<Columns>
<asp:BoundField DataField="IDNumber" HeaderText="IDNumber" ReadOnly="True"/>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"/>
<asp:BoundField DataField="LastName" HeaderText="LastName"/>
<asp:BoundField DataField="DOB" HeaderText="DOB"/>
<asp:BoundField DataField="Gender" HeaderText="Gender"/>
</Columns>
</asp:GridView>
</form>
</html>

On the button click event call this method
protected void ExportToExcel()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=GridView1.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter StringWriter = new System.IO.StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
GridView1.RenderControl(HtmlTextWriter);
Response.Write(StringWriter.ToString());
Response.End();
}

Related

How to save image in database and display it into Views in MVC 5?

I have a table like following
CREATE TABLE [dbo].[Movies] (
[fname] NVARCHAR(50) NULL,
[lname] NVARCHAR(50) NULL,
[MoviePoster] VARCHAR (50) NULL,
how to save image to movie poster field and how to view it
[MoviePoster] [varbinary](max) NULL
-- You have to insert image as a BLOB
-- Insert blob script :
INSERT INTO [Movies](MoviePoster)
VALUES (SELECT * FROM OPENROWSET (BULK 'your img url', SINGLE_BLOB))
--Display image in views:
<img src='data:image/jpeg;base64, <--data from db-->' />
How about saving movie poster on your server let's say:
/content/images/movieposters/thearrival.jpg
and storing in MoviePoster field only the filename thearrival.jpg
I personally prefer this approach because if let's say your database will grow and you will have more visitors ...well, you will be able to move all your movie posters to a different server and free up a lot of load from application server.
Creat an "Images" folder in Solution explorer.
Create an ADO.NET Entity Data Model (in this example is "Database1Entities")
Home Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace test2.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult FileUpload(HttpPostedFileBase file)
{
if (file != null)
{
Database1Entities db = new Database1Entities();
string ImageName = System.IO.Path.GetFileName(file.FileName);
string physicalPath =Server.MapPath("~/images/"+ ImageName);
// save image in folder
file.SaveAs(physicalPath);
//save new record in database
tblA newRecord = new tblA();
newRecord.fname = Request.Form["fname"];
newRecord.lname = Request.Form["lname"];
newRecord.MoviePoster = ImageName;
db.tblAs.Add(newRecord);
db.SaveChanges();
}
//Display records
return RedirectToAction("../home/Display/");
}
public ActionResult Display()
{
return View();
}
}
}
Index View
#{
ViewBag.Title = "Index";
}
#using (Html.BeginForm("FileUpload", "Home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<div>
First name<br />
#Html.TextBox("fname") <br />
Last name<br />
#Html.TextBox("lname") <br />
Image<br />
<input type="file" name="file" id="file" style="width: 100%;" /> <br />
<input type="submit" value="Upload" class="submit" />
</div>
}
DisplayView
#{
ViewBag.Title = "Display";
}
#{
test2.Database1Entities db = new test2.Database1Entities();
}
#using (Html.BeginForm())
{
<table border="1">
<thead>
<tr>
<th>Image</th>
<th>First name</th>
<th>Last name</th>
</tr>
</thead>
<tbody>
#foreach (var item in db.tblAs)
{
<tr>
<td><img src="~/images/#item.imageUrl" width="100" height="100" /> </td>
<td>#item.fname</td>
<td>#item.lname</td>
</tr>
}
</tbody>
</table>
}
The OutPut will be a table with viewed image from the database
Actually you can store the image on Db as well. You don't need to keep it on the server as a file if you don't want to (if you have lots of movies it would be a problem to manage).
If you are using SQL Server there is a "image" data type. If you are using MySql you should use BLOB.
I am using MVC, so:
The Model (partial code) (while in SqlServer you will declare image, inside the model the type will be byte[]:
public byte[] PersonImage { get; set; }
Inside the same model you are going to need a method to retrieve the path:
public string GetPicture()
{
if (PersonImage == null)
{
return null;
}
var base64Image = System.Convert.ToBase64String(PersonImage);
return $"data:{ImageContentType};base64,{base64Image}";
}
The create action inside the controller (The action declaration will need to receive an IFormFile PersonImage), on my case I am handling the image upload on the register action of my controller (Some of the controller code has been taken off to be more concise):
public async Task<IActionResult> Register(RegisterViewModel model, Client client, Employee employee, Person person, IFormFile PersonImage, string returnUrl = null)
if (PersonImage != null)
{
using (var stream = new MemoryStream())
{
await PersonImage.CopyToAsync(stream);
person.PersonImage = stream.ToArray();
person.ImageContentType = PersonImage.ContentType;
}
}
_context.Add(person);
await _context.SaveChangesAsync();
And now the view, you need to add the enctype to the form:
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form asp-route-returnUrl="#ViewData["ReturnUrl"]" method="post" enctype="multipart/form-data">
<h2 class="text-center font-weight-bold">Create a new account.</h2>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="#person.PersonImage" class="control-label"></label>
<input type="file" asp-for="#person.PersonImage" class="form-control" />
<span asp-validation-for="#person.PersonImage" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-default">Register</button>
</form>
</div>
<div class="col-md-4"></div>
</div>
Again, I took off most of the code to get a better and concise example. I had a hard time to find this when I was trying to put some images to the Db.
[HttpPost]
public ActionResult AddEmployee(HttpPostedFileBase file)
{
using(DbEntities DB = new DbEntities())
{
TblImage tblimg=new TblImage();
if (file != null)
{
var fileName = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("~/Data/EmployeeProfileImage/" + fileName));
tblimg.image = "~/Data/EmployeeProfileImage/" + fileName;
}
DB.TblImages.Add(tblimg);
DB.SaveChanges();
}
return View();
}
INDEX
#{
ViewBag.Title = "Index";
}
<link href="~/bootstrapp/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/bootstrapp/js/bootstrap.min.js"></script>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f1f1f1;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
<h2>Index</h2>
#using (Html.BeginForm("Index", "Candidate", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<div class="container">
<table>
<tr><td colspan="2" style="width:800px;height:50px">candidate</td></tr>
<tr><td>#*<label>Id</label><input type="number" name="candidateID" />*#</td></tr>
<tr>
<td style ="width:10px;height:10px">
<label>Name</label> <input type="text" name="Name" />
</td>
<td style="width:80px;height:50px"><label>Binary Image</label>
<input type="file" name="file1" id="file1" style="width: 100%;" /> <br />
</td>
</tr>
<tr>
<td>
<label>Address</label> <input type="text" name="address" />
</td>
<td>
<label>Path Image</label> <input type="file" name="file2" id="file2" style="width: 100%;" />
</td>
</tr>
<tr>
<td>
<label>JobProfile</label> <input type="text" name="JobProfile" />
</td>
<td>
<label>Email</label> <input type="text" name="email" />
</td>
</tr>
<tr><td>
<label>Phone No.</label> <input type="number" name="phone" />
</td><td ><input type="submit" value="Submit"/></td></tr>
</table>
</div>
}
#Html.Partial("~/Views/Candidate/detail.cshtml")
DETAIL
#*#model List< angularmvcdemo.CandidateDetail>*#
#using angularmvcdemo.Models;
<link href="~/bootstrapp/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/bootstrapp/js/bootstrap.min.js"></script>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f1f1f1;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
#{
modeldataEntities db = new modeldataEntities();
//angularmvcdemo.modeldataEntities db = new angularmvcdemo.modeldataEntities();
}
<table>
<tr><td colspan="2" style="width:800px;height:50px">candidate</td></tr>
#foreach(var detail in db.CandidateDetails){
<tr>
<td style="width:10px;height:10px">
<label>Name</label>#detail.Name
#*<input type="text" name="Name" />*# </td>
<td> binary image
#if (detail.BinaryPhoto != null)
{ var base64 = Convert.ToBase64String(detail.BinaryPhoto);
var imgsrc = string.Format("data:image/jpg;base64,{0}", base64);
<img src='#imgsrc' style="max-width:100px;max-height:100px" />
}
else { <img src="~/img/avatar-default.jpg" style="max-width:100px;max-height:100px" /> } </td>
</tr>
<tr>
<td>
<label>Address</label> #detail.address </td>
<td><label>path image</label>
#if(#detail.PathPhoto!=null){ <img src="#detail.PathPhoto" width="100" height="100" />
}else{ <img src="~/img/avatar-default.jpg" style="max-width:100px;max-height:100px" /> } </td>
</tr>
<tr>
<td>
<label>JobProfile</label>#detail.JobProfile </td>
<td>
<label>Email</label> #detail.email </td>
</tr>
<tr><td></td><td><label>Phone No.</label>
#detail.phone</td><</tr>
}
</table>

how to make a modal with asp mvc?

I have a question , I have in my view a form, this form contains a list , this list contains four attributes , vendor , application , product and value , these 4 we display only two ( as seen in the code) would like to display in a modal product and the value of the order , the list is displayed in the same position already has such data , how do I display that data through an action of my button that has the action " getFornecedor " ( this action has not yet been implemented , I do not know if it is necessary because the elements are in the same position in the list )
View
#model Test.Models.Order
<head>
<meta charset="utf-8" />
<title>Teste</title>
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">
<script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
#Styles.Render("~/Content/bootstrap.css")
#Scripts.Render("~/bundles/modernizr")
<style>
th {
height: 10px;
}
</style>
</head>
<body>
<div id="divbody">
<nav class="navbar navbar-inverse">
</nav>
#using (Html.BeginForm("Save", "Cab", FormMethod.Post))
{
<div class="table-responsive" id="table">
<table id="myTable" class="table table-striped" cellspacing="0">
<thead style="position:static">
<tr>
<th style="font-size:10px">SELECT</th>
<th style="font-size:10px">CONTACT</th>
<th></th>
<th style="font-size:10px">SUPPLY</th>
<th style="font-size:10px">ORDER</th>
</tr>
</thead>
#for (int i = 0; i < Model.listOrder.Count(); i++)
{
<tr>
<td align="center" height="2px">#Html.CheckBoxFor(m => m.listOrder[i].isEdit, new { #onclick = "habilit(" + i + ")", #id = "c" + i })</td>
<td colspan="2">
<a href="#Url.Action("getFornecedor", "MyController")" class="btn btn-xs btn-primary">
<i class="glyphicon glyphicon-phone-alt"></i>
</a>
<a href="#Url.Action("sendEmail", "MyController")" class="btn btn-xs btn-primary">
<i class="glyphicon glyphicon-envelope"></i>
</a>
</td>
<td height="2px"> #Html.TextBoxFor(m => m.listOrder[i].supply, new { #readonly = "readonly", #size = "18px", #class = "form-controlSupply" }) </td>
<td height="2px"> #Html.TextBoxFor(m => m.listOrder[i].order, new { #readonly = "readonly", #size = "75px", #class = "form-controlOrder" }) </td>
<td></td>
</tr>
}
</table>
</div>
<br />
<input type="submit" value="Salve" id="btn" disabled="disabled" class="btn btn-small btn-primary" />
}
</div>
</body>
</html>
MVC doesn`t have modal on fly .. (like control in web forms for example) i suggest you to use third party library , may be something like jquery UI .. You can see example here : https://jqueryui.com/dialog/
You just need client side event to show modal dialog. In that container you can put any data that you want.

Iterator in struts2 at dynamic input fields

I want to create a page in which input field appears dynamically depends upon select tag. For this I create a jsp file name receiptBudget.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://localhost:8088/Gpms/js/jquery-1.9.1_1.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery.inputlimiter.1.3.1.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery-ui.js"></script>
<script src="http://localhost:8088/Gpms/js/jquery.inputlimiter.1.3.1.min.js">
<script language="javascript">
function getrecpHead() {
var recpLedHead = document.getElementById('recpLedHead').value;
$.get("budget.action", {recpLedHead: $("#recpLedHead").val()}, displayBlocks);
}
function displayBlocks(response) {
if (response) {
$("#divBudget").html(response);
}
}
</script>
</head>
<body>
<s:form method="post" name="receiptBudget">
<table border="1">
<tr>
<td colspan="1"><div align="center">Date</div></td>
<td><div align="center"><label for="transDate" id="transDate">
<%=dateFormat.format(calobj.getTime())%></label></div>
</td>
<td><div align="center">Financial Year </div></td>
<td colspan="2"><div align="center"><label for="finyear" id="finyear">
<%=financialYear%></label></div>
</td>
</tr>
<tr>
<td colspan="2"><div align="center">LedgerHead Head </div></td>
<td colspan="3"> <div align="center">
<select name="recpLedHead" id="recpLedHead" onchange="getrecpHead()">
<option value="0">Select Ledger Head</option>
<%
String ledgerName;
for (int i = 0; i < ledlist.size(); i++) {
ledgerName = ledlist.get(i);
%>
<option value="<%=ledgerName%>"><%=ledgerName%></option>
<%}%>
</select>
</div></td>
</tr>
<tr>
<td width="76" colspan="1"><div align="center">CollectionHead</div></td>
<td width="117"><div align="center">Preceeding Year</div></td>
<td width="114"><div align="center">Current Year </div></td>
<td width="112"><div align="center">Next Year </div></td>
<td width="112"><div align="center">Remarks </div></td>
</tr>
</table>
<table>
<s:form action="budgetSave">
<div id="divBudget">
</div>
<tr>
<td colspan="1"><s:submit value="save"></s:submit></td>
</tr>
</s:form>
</table>
</s:form>
</div>
</body>
</html>
--------------and calling jsp through action class is getRecpHead.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table>
<s:iterator value="mxplist" id="mxplist">
<tr>
<td><s:textfield name="collectionHead" theme="simple"/></td>
<td><s:textfield name="receiptOn" theme="simple"/></td>
<td><s:textfield name="plan" theme="simple"/></td>
<td><s:textfield name="budgeted" theme="simple"/></td>
</tr>
</s:iterator>
</table>
</body>
action file is ReceiptBudget.java
public class ReceiptBudget extends ActionSupport {
private HttpServletRequest request;
private HttpServletResponse response;
List<MasterCollectionhead> mxplist;
public ReceiptBudget() {
}
#Override
public String execute() throws Exception {
HttpSession hs = request.getSession();
UserMaster user = (UserMaster) hs.getAttribute("user");
String recpHead = request.getParameter("recpLedHead");
System.out.println("receipt"+recpHead);
SessionFactory sf = GpmsHibernateUtil.getSessionFactory();
Session sess = sf.openSession();
Transaction tx = sess.beginTransaction();
Query qq = sess.createQuery("from MasterCollectionhead as mba where mba.ledgerId "
+ " in (SELECT mlh.id.ledgerId FROM MasterLedgerhead mlh WHERE mlh.admHead = ? and
+" mlh.id.gpCode = ?) "
+ " and mba.id.gpCode = ?");
qq.setString(0, recpHead);
qq.setString(1, user.getGpCode());
qq.setString(2, user.getGpCode());
mxplist = (List<MasterCollectionhead>)qq.list();
return "success";
}
public String save() throws Exception {
System.out.println("mxplist"+mxplist.size());
return "success";
}
public List<MasterCollectionhead> getMxplist() {
return mxplist;
}
public void setMxplist(List<MasterCollectionhead> mxplist) {
this.mxplist = mxplist;
}
#Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
#Override
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
}
and the struts.xml tag is
<action name="budget" class="com.gpms.ReceiptBudget" method="execute">
<result name="success">/budget/getRecpHead.jsp</result>
<result name="input">/budget/receiptBudget.jsp</result>
</action>
<action name="budgetSave" class="com.gpms.ReceiptBudget" method="save">
<result name="success">/budget/receiptBudget.jsp</result>
<result name="input">/budget/home.jsp</result>
</action>
finally i want to save data entered in textbox appeard through iterator

Display of image in show page

I have option of photo upload in my create.gsp page. I'm able to see the uploaded photo in my create page and able to upload my photo in database, but cannot see that photo in my show page.
This is create.gsp page
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="billing-without-grid" />
<g:set var="entityName"
value="${message(code: 'skeletonBill.label', default: 'SkeletonBill')}" />
<title><g:message code="default.create.label"
args="[entityName]" /></title>
<script>
function showPhoto(imageFile) {
var fileReader = new FileReader();
var image = document.getElementById("uploadPhotoFile");
fileReader.onload = function(e) {
image.src = e.target.result;
}
fileReader.readAsDataURL(imageFile.files[0]);
}
</script>
</head>
<body>
<div class="body">
<div class="container-fluid">
<div class="row">
<div class="span6">
<img src="" name="uploadPhotoFile" id="uploadPhotoFile"
height="200" width="160" />
<table style="width: 25%">
<tbody>
<tr class="prop">
<td valign="top" class="name"><label for="uploadPhoto"><g:message code="uploadInformation.uploadPhoto.label" default="Upload Photo" /></label></td>
<td valign="top" class="value ${hasErrors(bean: uploadInformationInstance, field: 'uploadPhoto', 'errors')}">
<input type="file" id="uploadPhoto" name="uploadPhoto" onchange="showPhoto(this)" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html> '
Domain class that I created
class UploadInformation {
static constraints = {
uploadPhoto(nullable:true, maxSize: 16384 /* 16K */)
}
byte[] uploadPhoto
static transients = ["uploadPhoto"]
static mapping = {
uploadPhoto column:"uploadPhoto",sqlType: "blob"
}
}
Anuj.
The problem I see after quick look at your code is:
static transients = ["uploadPhoto"]
UploadPhoto will not be saved to database because it's declarated as transient.
See more details transient properties

Nested Datalists using stored procedure parameters

I'm working with some nested datalist controls and cannot get the SP parameters for my nested stored procedure to work.
In debug I can see that SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString()); is getting the correct value from the label but when the results display I always get the results for the last parameter added?
I'm guessing I need to clear the parameters in some way each time the nested datalist is bound but if I add code to do that it results in an error that I have not specified the parameters?
My code is below, you'll see that eventually I will have 3 nested datalists inside each other - or that's the plan.
Thanks for any suggestions
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="nhscsharprepeater._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Import Namespace="System.Web" %>
<%# Import Namespace="System.Web.UI" %>
<%# Import Namespace="System.Data" %>
<script type="text/C#" runat="server">
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataList oList = (DataList)e.Item.FindControl("Datalist2");
Label oLabel = (Label)e.Item.FindControl("lblSection");
DataList oList2 = (DataList)oList.FindControl("Datalist3");
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectCommand = "report_DistinctSubSections";
SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString());
oList.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_DistinctSection" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="Section" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_getReports" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="SubSection" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="2" RepeatDirection="Horizontal" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Section") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist2" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "SubSection") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist3" runat="server" DataSourceID="SqlDataSource3">
<ItemTemplate>
<!--<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Report") %>' ID="lblSection">
</asp:Label>-->
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
One might guess that calling Clear on SqlDataSource2.SelectParameters before calling Add might do the trick.

Resources