我正在使用microsoft sql server 2005&有一个下拉列表数据绑定到一个有几条记录的表。在下拉列表的选定索引更改中,我希望我的转发器重新数据绑定仅显示与下拉列表中所选值具有相同ID的记录。
这是我的下拉列表:
<asp:DropDownList ID="ddlViewLabel" runat="server" Width="280px"
DataSourceID="sdsLabels" DataTextField="LabelName" DataValueField="LabelID"
onselectedindexchanged="ddlViewLabel_SelectedIndexChanged">
</asp:DropDownList>
这是我的转发器:
<asp:Repeater ID="rptDocuments" runat="server" OnItemCommand="viewDocument_ItemCommand"
DataSourceID="sdsDocuments">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div class="nav-rpt">
<asp:LinkButton ID="lnkDocumentTitle" Text='<%# Bind("DocumentTitle") %>' runat="server"
CommandArgument='<%# Eval("DocumentID") %>' CssClass="nav-rpt-btn"></asp:LinkButton>
<img src="Images/ARROW.png" style="float: right" />
</div>
</ItemTemplate>
<SeparatorTemplate>
<div style="border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;">
</div>
</SeparatorTemplate>
<FooterTemplate>
<div style="border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;">
</div>
</FooterTemplate>
</asp:Repeater>
以下是我的2个数据来源:
<asp:SqlDataSource ID="sdsDocuments" runat="server" ConnectionString="<%$ ConnectionStrings:blcDocumentationConnectionString %>"
SelectCommand="SELECT [DocumentID], [DocumentTitle], [DocumentBody], [ModifiedDate], [CreatedDate] FROM [tblDocument]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsLabels" runat="server" ConnectionString="<%$ ConnectionStrings:blcDocumentationConnectionString %>"
SelectCommand="SELECT [LabelID], [LabelName] FROM [tblLabel]"></asp:SqlDataSource>
<asp:SqlDataSource ID="sdsLink" runat="server"
ConnectionString="<%$ ConnectionStrings:blcDocumentationConnectionString %>"
SelectCommand="SELECT [LabelID], [DocumentID], [LinkID] FROM [tblLink]"></asp:SqlDataSource>
在哪里输入逻辑来过滤转发器,使用正确的'LabelID'显示'Documents'?
答案 0 :(得分:0)
您需要在下拉列表中为您定义的ddlViewLabel_SelectedIndexChanged方法编写一些代码
protected void ddlViewLabel_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList d = (DropDownList)sender;
// psudeo code from here on out
// get the DropDownList selected index
// create the new SQL statement
// either create a new SQlDataSource or SqlCommand/SqlConnection objects, set the sql, attach them to the repeater, bind
}