Solved

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

Posted on 2014-03-17
4
823 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Desktop Application 3 54
Getting error in connectionstring with Excel. 30 45
Call Controller Action Method from ASPX 2 22
Need a simple RegEx to search for two words 27 42
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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