I found this nifty code snippet and modified it with my values. Getting this error now: The name cblAuthorsList does not exist in the current context. Confused why since this is on my page. How do I resolve this error?
Code:
private void FindAllOfMyString(string searchString)
{
// Set the SelectionMode property of the ListBox to select multiple items.
cblAuthorsList.SelectionMode = SelectionMode.MultiExtended;
// Set our intial index variable to -1.
int x = -1;
// If the search string is empty exit.
if (searchString.Length != 0)
{
// Loop through and find each item that matches the search string.
do
{
// Retrieve the item based on the previous index found. Starts with -1 which searches start.
x = cblAuthorsList.FindString(searchString, x);
// If no item is found that matches exit.
if (x != -1)
{
// Since the FindString loops infinitely, determine if we found first item again and exit.
if (cblAuthorsList.SelectedIndices.Count > 0)
{
if (x == cblAuthorsList.SelectedIndices[0])
return;
}
// Select the item in the ListBox once it is found.
cblAuthorsList.SetSelected(x, true);
}
} while (x != -1);
}
}
<asp:CheckBoxList ID="cblAuthorsList" runat="server" Text='<%# Bind("Authors") %>' SelectionMode="Multiple" DataSourceID="odsAuthors" DataTextField="Name" DataValueField="Name"
AppendDataBoundItems = "true" AutoPostBack="true">
<asp:ListItem Text="All Authors" Value="All Authors" />
</asp:CheckBoxList>