سؤال

Using a SQL datasource to filter the options in drop down list from an onclick link button

Ultimately I have a drop down list that show all individuals. I'm wanting the user to be able to click a link button(A-Z) so the options in the drop down list only hold the names that fall into the link button's category. SP is already written just unsure of how exactly to tie the link button and drop down list with out writing code per link button. I'm wanting to use a data view for this. So on my aspx page I have the datasource set up and pointing to the drop down list but not sure on how to code it..

هل كانت مفيدة؟

المحلول

Lets say that you have a datatable with columns ID and NAME.
Then in its link button you can use :

    Private Sub FilterNames(ByVal letter As String)
    Dim items = (From p In dt
            Select New With {.Name = p.Field(Of String)("NAME"),
                             .ID = p.Field(Of Integer)("ID")}).ToList()

    Dim filtered = items.Where(Function(x) x.Name.ToUpper.StartsWith(letter)).ToList()

    ComboBox1.DataSource = filtered
    ComboBox1.DisplayMember = "NAME"
    ComboBox1.ValueMember = "ID"
End Sub
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top