Solved

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

Posted on 2014-03-17
4
846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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