I am using microsoft sql server 2005 & have a drop down list databound to a table with a few records. On 开发者_如何学编程the selected index change of the drop down list, I want my repeater to re-databind only displaying records that have the same ID as the selected value in the drop down list.
Here is my drop down list:
<asp:DropDownList ID="ddlViewLabel" runat="server" Width="280px"
DataSourceID="sdsLabels" DataTextField="LabelName" DataValueField="LabelID"
onselectedindexchanged="ddlViewLabel_SelectedIndexChanged">
</asp:DropDownList>
Here is my repeater:
<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>
Here are my 2 data sources:
<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>
Where do I enter logic to filter the repeater from displaying 'Documents' with the correct 'LabelID' ?
You need to write some code for your defined ddlViewLabel_SelectedIndexChanged method on the dropdownlist
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
}
精彩评论