[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 906
  • Last Modified:

'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'FindStringExact'

I am getting the following error:
'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'FindStringExact' and no extension method 'FindStringExact' accepting a first argument of type 'System.Web.UI.WebControls.DropDownList'
could be found.
int intCboIndex = cboServers.FindStringExact(LocalServerName);// error here
Thanks in advance for any help given.
Below is the complete code for clarity.
protected void btnSearch_Click(object sender, EventArgs e)
    {
        //Cursor = Cursors.WaitCursor;
        //get a DataTable of the servers
        DataTable dtList = SMOUtilities.ListAllKnownInstances();
        foreach (DataRow dr in dtList.Rows)
        {
            String ServerName;
            ServerName = dr["Server"].ToString();
            if (!String.IsNullOrEmpty(dr["Instance"].ToString()))
            {
                ServerName += @"\" + dr["Instance"].ToString();
            }
            if (cboServers.Items.IndexOf(ServerName) < 0)// error here
            {
                cboServers.Items.Add(ServerName);
            }
        }
        //  By default select the local server
        Server LocalServer = new Server();
        String LocalServerName = LocalServer.Name;
        if (!String.IsNullOrEmpty(LocalServer.InstanceName))
        {
            LocalServerName += @"\" + LocalServer.InstanceName;
        }
        int intCboIndex = cboServers.FindStringExact(LocalServerName);// error here
        if (intCboIndex >= 0)
        {
            cboServers.SelectedIndex = intCboIndex;
        }
        //Cursor = Cursors.Default;
    }

Open in new window

0
homeshopper
Asked:
homeshopper
  • 2
1 Solution
 
AndyAinscowCommented:
Basically that means the function does not exist.
You need to use a different function.
0
 
Carl TawnSystems and Integration DeveloperCommented:
The Items collection support FindByText and FindByValue methods. But you need to chain a couple of methods to get the index:
int indexCboIndex = cboServers.Items.IndexOf(cboServers.Items.FindByText(LocalServerName));

Open in new window

For info: The FindStringExact method applies to the ComboBox control in WinForms development, it isn't valid for the DropDownList in ASP.Net.
0
 
homeshopperAuthor Commented:
Thanks, it now all works.
0
 
homeshopperAuthor Commented:
I thought it might be something to do with the conversion of winforms to asp.net
I did not know what other function could used. Thank you for the solution.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now