本文介绍了如何将数据显示到列表中从数据库查看。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Team,
我正在制作一个简单的基于Windows的C#应用程序
我有一个表EMP包含一些数据,如
姓名教育电子邮件电话
John BE [email protected] 1234
我有一个ListView控件和文本框用于搜索目的。
当我在文本框控件中输入John然后单击搜索按钮后....我想将John的数据从EMP表显示到listview控件中。
请帮助我。
Hi Team,
I am making one simple Windows based C# application
I have one table "EMP" which contains Some data like-
Name Education Email Phone
John BE [email protected] 1234
I have One ListView control and Textbox for search purpose.
when I enter John in textbox control then after clicking search button ....I want to show data for John from "EMP" table into listview control.
Please help me.
推荐答案
protected void btnSearch_Click(object sender, EventArgs e)
{
string name = txtbox.Text;
// use this name to get the data from database.
// and assign it to the listview.. as below..
}
listView1.View = View.Details;
listView1.Columns.Add("Name",100);
listView1.Columns.Add("Education",100);
listView1.Columns.Add("Email",100);
listView1.Columns.Add("Phone", 100);
listView1.Items.Clear();
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Columns.Add("Email", typeof(string));
dt.Columns.Add("Phone", typeof(string));
dt.Rows.Add("karthik", "B.E CSE", "[email protected]", "98800");
dt.Rows.Add("parthip", "B.S Mech", "[email protected]", "98800");
foreach (DataRow row in dt.Rows)
{
ListViewItem li = new ListViewItem(row.ItemArray.Select(k => k + "").ToArray());
listView1.Items.Add(li);
}
这篇关于如何将数据显示到列表中从数据库查看。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!