如何在asp.net中将数据从Asp Table显示到GridView [英] How do I display data from Asp Table to a GridView in asp .net
本文介绍了如何在asp.net中将数据从Asp Table显示到GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨亲爱的所有
有谁能告诉我如何在asp .Net中将Asp表中的数据显示给GridView
谢谢
Hi Dear All
Could anyone please tell me how to show data from an Asp Table to a GridView in asp .Net
Thank You
推荐答案
HTML code
HTML code
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
<columns>
<asp:boundfield datafield="Id" headertext="Id" />
<asp:boundfield datafield="Name" headertext="Name" />
</columns>
</asp:gridview>
C# Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string))});
dt.Rows.Add(1, "Ramesh","India");
dt.Rows.Add(2, "Suresh","India");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
这篇关于如何在asp.net中将数据从Asp Table显示到GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文