本文介绍了后面的datagridview代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在Windows窗体中将表绑定到datagridview并以窗体加载方式显示它...我不能使用智能标记,只能使用后面的代码.
感谢您的帮助.
I need to know how to bind a table to a datagridview in a windows form and display it in form load...i cant use the smart tag, only the code behind.
thank for your help.
推荐答案
tab.Columns.Add("ID", typeof(string));
tab.Columns.Add("value", typeof(string));
tab.Rows.Add("1", "No records found"
);
gridview1.datasource = tab;
希望这对您有帮助...
);
gridview1.datasource=tab ;
hope this will help u ...
try
{
string str = "select ReqId,FileNo,ReqControlNo,Requester,ReqDate,ReqTime,IssueDate,IssueTime,ReceivedDate,ReceiveTime from Issue where ReceivedDate between '" + txtReqDatefrom.Text + "' and '" + txtReqTo.Text + "' AND ReqControlNo='" + Session["ReqControlNo"].ToString() + "' order by ReceivedDate";
}
SqlDataAdapter da = new SqlDataAdapter(str, Db.GetConnection());
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
da.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
GridView1.Visible = true;
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
}
note:将Db.GetConnection()替换为您的连接对象
这篇关于后面的datagridview代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!