Solved

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

Posted on 2014-03-17
4
799 Views
Last Modified: 2014-03-17
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
Comment
Question by:homeshopper
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39933990
Basically that means the function does not exist.
You need to use a different function.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39934006
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
 

Author Comment

by:homeshopper
ID: 39934079
Thanks, it now all works.
0
 

Author Closing Comment

by:homeshopper
ID: 39934082
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now