文本框值将检查DropDownList值是否存在 [英] textbox value will check DropDownList value is there or not
问题描述
我对textbox.text值检查dropdownlist值检查有问题吗?帮帮我.
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";
}
无法将类型为"System.Web.UI.WebControls.ListItem"的对象转换为类型为"System.IConvertible"的对象.
Unable to cast object of type ''System.Web.UI.WebControls.ListItem'' to type ''System.IConvertible''.
thanks karthikeyan, bangalore.
推荐答案
女巫行引发了异常吗?
第一个问题:如果语句是incoret,则在比较时必须使用==而不是单个=.像这样:
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:
if (tt == true)
{
}
第二个问题:FindByText返回为ListItem而不是Text.试试这个:
2nd Problem: FindByText returns as ListItem instead of Text. Try this:
bool tt = Convert.ToBoolean(DropDownList1.Items.FindByText(TextBoxNew.Text).Text);
ps:我不在Visual Studio的后面,所以我不知道答案的正确性
ps: I am not behined Visual studio so i do not know the accuarty of the answer
错误必须在以下行中:
Error must be in this line:
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.
Hai,
答案是...
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.
Karthikeyan Bangalore.
这篇关于文本框值将检查DropDownList值是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!