This is a migrated thread and some comments may be shown as answers.

ShowDropDown problem

1 Answer 74 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jeff Clark
Top achievements
Rank 1
Jeff Clark asked on 26 Jul 2011, 10:51 PM
I am using a RadDropDownList (Q2 2011) as a search box to find a student. The user types in a name into the RadDropDownList and either hits the enter key or clicks a button.

I am using the KeyPress event to test for the enter key.  Both the KeyPress event and the button click event call a FindStudent routine.

The FindStudent routine retrieves data from a database and populates the RadDropDownList using a for loop and adding an object to the list with .Items.Add method. At the end of the routine it calls the ShowDropDown() method.

If I type in the RadDropDownList and click on the button, the drop down shows correctly.  If I type in the RadDropDownList and hit the Enter key the drop down shows and then immediately disappears.

How can I get the drop down to stay when hitting the enter key?  Thanks for your help.

Below is my code for the KeyPress event, Button Click event and FindStudent routine.
private void FindStudent_Btn_Click(object sender, EventArgs e)
{
    string fsText = FindStudent_DDL.Text;
    FindStudent_DDL.Items.Clear();
    FindStudent(fsText);
}

private void FindStudent_DDL_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
        string fsText = FindStudent_DDL.Text;
        FindStudent_DDL.Items.Clear();
        FindStudent(fsText);
    }
}

private void FindStudent(string fsText)
{
    ... code that retrieves data from database and populates a DataTable dt ...
     
    if (dt.Rows.Count > 0)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            StudentObject student = new StudentObject(dt.Rows[i]["id_num"].ToString(), dt.Rows[i]["last_name"].ToString(), dt.Rows[i]["first_name"].ToString());
            FindStudent_DDL.Items.Add(new RadListDataItem(student.ToString(), student));
        }
    }
 
    FindStudent_DDL.ShowDropDown();
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Jeff Clark
Top achievements
Rank 1
answered on 27 Jul 2011, 06:56 PM
I solved the problem. In my initial testing I had previously set the AutoCompleteMode property to suggest and that was causing the disappearance of the Dropdown.
Tags
DropDownList
Asked by
Jeff Clark
Top achievements
Rank 1
Answers by
Jeff Clark
Top achievements
Rank 1
Share this question
or