简体   繁体   English

根据列中的值进行数据绑定中继器

[英]Databind Repeater based on value in column

I am using microsoft sql server 2005 & have a drop down list databound to a table with a few records. 我正在使用Microsoft SQL Server 2005&有一个下拉列表数据绑定到具有一些记录的表。 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. 在下拉列表的选定索引更改上,我希望我的转发器仅对与下拉列表中的选定值具有相同ID的记录进行重新数据绑定。

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: 这是我的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>

Where do I enter logic to filter the repeater from displaying 'Documents' with the correct 'LabelID' ? 我在哪里输入逻辑来过滤转发器,以使其不显示带有正确“ LabelID”的“文档”?

You need to write some code for your defined ddlViewLabel_SelectedIndexChanged method on the dropdownlist 您需要在下拉列表中为定义的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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM