后面的datagridview代码 [英] datagridview code behind
本文介绍了后面的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.
推荐答案
此链接绝对可以帮助您
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx [ ^ ]
This link definitely help you
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx[^]
我不了解您的问题.请您详细解释
DataTable选项卡= new DataTable();
I am not understanding your problem . It will good if u explain in detail
DataTable tab = new DataTable();
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 on page load like this
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代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文