How do I display information in my page (take it from DB) in asp.net 2008
如何在asp.net 2008中显示我的页面中的信息(从数据库中取出)
Currently I use GridView, but it display the information in a TABLE. I want to display it in a normal line.
目前我使用GridView,但它在TABLE中显示信息。我想以正常的方式显示它。
for example: I have this table in my DB
例如:我的数据库中有这个表
http://www.rofof.com/img2/4jpqfn26.gif
alt text http://www.rofof.com/img2/4jpqfn26.gif
替代文字http://www.rofof.com/img2/4jpqfn26.gif
I want to print an information in my page as:
我想在我的页面中打印信息:
You are A and your ID is: 1
你是A,你的身份证是:1
without using GridView.
不使用GridView。
1 个解决方案
#1
How are you getting your data from the database to your gridview? Also do you want to display only a single record or would you display multiple records?
您是如何将数据从数据库获取到gridview的?您还想只显示一条记录还是要显示多条记录?
The Repeater is a great control if you want to display all the records. You can bind it the same way your binding the grid then define your template to render the html however you want.
如果要显示所有记录,Repeater是一个很好的控件。您可以像绑定网格一样绑定它,然后定义模板以呈现您想要的html。
If you only want to display a single record you could just do this in the code behind of the page. For example:
如果您只想显示单个记录,则可以在页面后面的代码中执行此操作。例如:
Page_Load()
{
if (!IsPostBack) //Make sure this only runs first time we call page
{
//Get your data from the DB, can't help here unless
//you provide more details.
MyData data=....
myLabel.Text="You are " + data["name"].ToString() ....
}
}
If you update your question with more details about your data source (are you using a data table custom objects etc...). I can update my answer with a better exampkle
如果您使用有关数据源的更多详细信息更新您的问题(您使用的是数据表自定义对象等吗?)。我可以用更好的exampkle更新我的答案
#1
How are you getting your data from the database to your gridview? Also do you want to display only a single record or would you display multiple records?
您是如何将数据从数据库获取到gridview的?您还想只显示一条记录还是要显示多条记录?
The Repeater is a great control if you want to display all the records. You can bind it the same way your binding the grid then define your template to render the html however you want.
如果要显示所有记录,Repeater是一个很好的控件。您可以像绑定网格一样绑定它,然后定义模板以呈现您想要的html。
If you only want to display a single record you could just do this in the code behind of the page. For example:
如果您只想显示单个记录,则可以在页面后面的代码中执行此操作。例如:
Page_Load()
{
if (!IsPostBack) //Make sure this only runs first time we call page
{
//Get your data from the DB, can't help here unless
//you provide more details.
MyData data=....
myLabel.Text="You are " + data["name"].ToString() ....
}
}
If you update your question with more details about your data source (are you using a data table custom objects etc...). I can update my answer with a better exampkle
如果您使用有关数据源的更多详细信息更新您的问题(您使用的是数据表自定义对象等吗?)。我可以用更好的exampkle更新我的答案