Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have problem for textbox.text value check dropdownlist value check? help me.
bool tt = Convert.ToBoolean(DropDownList1.Items.FindByText(TextBoxNew.Text));
                if(tt = true)
{
label.text ="name not exist";
}
else
{
label.text ="name exist";
}

Unable to cast object of type 'System.Web.UI.WebControls.ListItem' to type 'System.IConvertible'.

thanks karthikeyan, bangalore.
Posted
Updated 12-Dec-10 23:49pm
v2
Comments
Toniyo Jackson 13-Dec-10 5:49am    
Always put your code inside code block.

Hai ,
Answer is...
protected void Button1_Click(object sender, EventArgs e)
    {
        //bool tt = Convert.ToBoolean(DropDownList1.Items.FindByText(TextBoxNew.Text));
        ListItem tt = DropDownList1.Items.FindByText(TextBoxNew.Text);
        if (tt == null)
        {
            label.Text = "name not exist";
        }
        else
        {
            label.Text = "name exist";
        }
    }


Karthikeyan Bangalore.
 
Share this answer
 
v2
Comments
Toniyo Jackson 13-Dec-10 5:51am    
Always put your code inside code block
pkarthionline 13-Dec-10 6:28am    
Previous i got this error.
Unable to cast object of type 'System.Web.UI.WebControls.ListItem' to type 'System.IConvertible'.

now ok.
senguptaamlan 13-Dec-10 6:42am    
please mark this thread as answer....by doing that it will help other as well as the author :)
Error must be in this line:
C#
bool tt = Convert.ToBoolean(DropDownList1.Items.FindByText(TextBoxNew.Text));

Clearly you are trying to use a bool convert on a dropdown listitem's text. Not allowed.

Just find the text and if you don't find then it does not exist or else exist.
 
Share this answer
 
witch line was it that threw exception?

1st Problem: if statement is incoret, when you compare you must use == instead of a single =. Like this:

C#
if (tt == true)
{
}


2nd Problem: FindByText returns as ListItem instead of Text. Try this:

C#
bool tt = Convert.ToBoolean(DropDownList1.Items.FindByText(TextBoxNew.Text).Text);


ps: I am not behined Visual studio so i do not know the accuarty of the answer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900