在asp.net页面中显示数据 [英] Display data in a asp.net page

查看:183
本文介绍了在asp.net页面中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不同的地方显示数据库中的数据.我正在使用datareader读取数据和存储的数据,如下所示:

I want to display data from database in different places. I am using datareader to read the data and stored data like this:

string name=dr["name"].ToString();


然后我在源代码页面中的<=%name%>这样的网页编写代码中显示数据.
有一个问题,如果我需要100列数据,那么我需要使用100个变量来声明和存储数据.

因此,请任何人都可以告诉我其他简单的操作步骤.

在此先感谢


我们可以在源代码中访问datareader值吗?
如果可以,怎么办?


then i display the data in webpage writing code like this <=%name%> in source page.
There is a problem that if i need 100 columns of data then i need to use 100 variables to declare and store the data.

so please any one can tell me any other simple procedure to do that.

Thanks in advance


can we access datareader value in source code?
if can then how?

推荐答案

您可以使用

you can use

<![CDATA[<%= dr["name"].ToString() %>]]>




如果您具有不同的字段,则必须使用不同的变量.
或者,如果您对一组变量重复相同的变量,则可以使用中继器控件.


if your having different fields you have to use different variables.
or if you have same variables repeating for a number of set the you can use repeater control.


任何不希望使用 http://aspalliance.com/757_Code_Snip_Populating_GridView_Control_Using_ASPNET_and_C_with_MouseOver_Effect.2 [
Any reason why you wouldn''t want to use a Grid View[^] or one of the other data binding controls?

Instead of using a DataReader, populate a DataSet or DataTable then simply bind to the grid.

You can have the grid autopopulate the columns, so no need for variables or anything like that

E.g. something like this

http://aspalliance.com/757_Code_Snip_Populating_GridView_Control_Using_ASPNET_and_C_with_MouseOver_Effect.2[^]


这篇关于在asp.net页面中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆