ASPX 页面显示 SQL 表中的多条记录(DetailsView 方法)
场景:在 Page1.aspx 中,用户提交邮政编码和邮政编码。城市和点击进入。然后,我将控件传递给带有 zipcode & 的 Page2.aspx。城市。
在第 2 页中,我将从与邮政编码和邮政编码相匹配的表中进行查询。城市。如果找到的话,我会得到1到n条记录。
现在我需要以下面的方式显示记录。
客户名称:Customer1
客户电话:201201201
客户城市:NewCity
客户名称:Customer2
客户电话:303013010
客户城市:OldCity
客户名称:Customer3
客户电话:45646466
客户城市:CurrentCity
上面的每条记录都是两列,第一列作为标题,第二列作为标题价值。我想在一个页面中显示最多 8 个客户(上面我显示了 3 个客户),然后输入页码。单击下一页,显示下一组 8 条记录。
请建议最好的控制。我想到了DetailsView,但不知道是否可以使用Detailsview 在一页中显示最多8 个匹配项。
请建议或任何其他替代方案。
Scenario : In Page1.aspx, user submits zipcode & City and hits enter. I then pass the control to Page2.aspx with zipcode & City.
Here in page2, I will query from a table matching the zipcode & City. If found, I will get 1 to n records.
Now I need to display records in the below fashion.
Customer Name : Customer1
Customer Phone : 201201201
Customer City : NewCity
Customer Name : Customer2
Customer Phone : 303013010
Customer City : OldCity
Customer Name : Customer3
Customer Phone : 45646466
Customer City : CurrentCity
Each record above is two columns with first column as header and second the value. I would like to show upto 8 customers (above I have shown 3 customers) in a page and then put the page numbering. Clicking on next page, shows the next set of 8 records.
Please suggest the best control. I thought of DetailsView but do not know if I can show up to 8 occurrences in one page using Detailsview.
Please suggest or any other alternatives.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是如何使用 Repeater 控件显示结果的示例...
ASP.NET Repeater 与 AlternatingItemTemplate、SeparatorTemplate、HeaderTemplate 和 FooterTemplates 以及 ItemTemplate 一起使用。
在代码隐藏文件中,以下代码用于创建一个 DataTable,然后创建一些简单的数据放入 DataTable 中以用于演示目的,然后我们将其绑定到 Repeater。在现实世界中,您将把 Repeater 绑定到数据库调用的结果,甚至可能是 XML 文件。
输出是这样的......
我希望它能帮助你......
This is example how to display the results using repeater control....
ASP.NET Repeater used with the AlternatingItemTemplate, SeparatorTemplate, HeaderTemplate and FooterTemplates as well as the ItemTemplate.
In the code behind file, the following code is used to create a DataTable and then create some simple data to put into the DataTable just for demonstration purposes, which we then bind to the Repeater. In the real world you'll be binding your Repeater to the results of a database call or maybe even an XML file.
and the out put is like this ....
I hope it will helps you....
您可以为此使用任何模板化数据绑定控件,例如 DataList 或 DataRepeater。
尝试将其添加到页面,然后右键单击选择“编辑项目模板”命令。然后,您可以添加所需的所有控件,例如案例中的标签。
You can use any templated databound control for this like DataList or DataRepeater.
Try to add it to the page and from right click select Edit item template command. Then you can add all controls you need like labels in your case.