如何验证asp.net中的文本框 [英] how to validate the textbox in asp net
本文介绍了如何验证asp.net中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用我的数据表验证文本框。
i想要在数据表中验证所有文本框值。
EX-001,002在我的表中任何一个重新输入001。我想要它?
I want to validate the textbox using my data table.
i want to validate text box value all ready in data table.
EX-001,002 in my table Any one reEnter the 001 .i want to vaild it??
推荐答案
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("----"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM TEST WHERE ID='"+TextBox1.Text+"'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DT = new DataTable();
da.Fill(DT);
con.Close();
if (DT.Rows.Count > 0)
{
Response.Write("ALREADY HAVE");
}
else
{
//YOUR CODE//
}
}
}
hi,
您可以使用下面的Lambda表达式进行检查。
You can check using Lambda expression as below.
if(objdt.AsEnumerable().Where(c => c.Field<string>("Col1") == txtbox1.Text.Trim()).Count() > 0)
{
//valid text
}
else
{
//invalid text
}
//Col1 is the column in your datatable.</string>
这将检查数据表中是否存在textbox值,如果count> gt; 0,然后该值存在于表中,否则不存在。
有关lambda表达式的更多信息 [ ^ ]
希望它有所帮助。
this will check the existence of the textbox value in datatable, if count > 0 , then that value exists in table else not.
More on lambda expression[^]
hope it helps.
这篇关于如何验证asp.net中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文