我正在使用一些嵌套的datalist控件,无法获取嵌套存储过程的SP参数。
在debug中我可以看到SqlDataSource2.SelectParameters.Add(“Section”,oLabel.Text.ToString());从标签中获取正确的值,但是当结果显示时,我总是得到最后一个参数的结果?
我猜我每次绑定嵌套的datalist时都需要以某种方式清除参数但是如果我添加代码来执行此操作会导致错误,我没有指定参数?
我的代码在下面,你会看到我最终会有3个嵌套的数据列表 - 或者说是计划。
感谢您的任何建议
<%@ 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>