创建一个表并从两个数据库表动态绑定到中继器
我正在为我的企业开发 CMS 系统,并且需要能够在控制面板中动态生成通知。请注意,我使用的是 .NET 2.0,使用 VB 进行编码,我的数据全部保存在 MySQL 数据库中。
对于大多数方面来说,这都非常简单,但由于整个事情是动态的,所以有些事情被证明更加困难。
我有一组
使用转发器动态生成的标签,如下所示:
<asp:Repeater runat="server" ID="locationRepeater">
<ItemTemplate>
<p id='locationNotification' title="<%# Container.DataItem %>" runat='server'>
COUNT DATA NEEDS TO GO HERE
</p>
<div class="jewelDescription" id="locationQuestionsNote" runat='server'>
Notification pending for <%# Container.DataItem %> <!-- (gives location name) -->
</div>
</ItemTemplate>
</asp:Repeater>
目前,Container.DataItem 从位置名称列表的非常简单的 dataBind 中为我提供位置名称
Dim locationList As Array = Split("1,2,3", ",")
locationRepeater.DataSource = locationList
locationRepeater.DataBind()
这很棒,它允许添加位置并从系统中删除后,控制面板会根据当前使用的位置数量自动更新。
但是...我在这里没有获得实际数据,这应该是来自单独数据库表的记录计数。
数据真的非常非常简单,我需要做的就是在转发器的每个循环期间查询 MySQL 数据库上的表以获取 ID WHERE locationName = Container.DataItem 的 COUNT 个...但我不知道如何做到这一点。
我想也许我必须先这样做,以某种方式在内存中创建一个表,但我担心我不知道如何实现这一点。
有没有人有类似的例子,它有点绑定到来自两个数据源的转发器......每个任务都非常简单,但我不知道如何将它们放在一起!
I am working on a CMS system for my business, and need to be able to generate notifications dynamically into a control panel. Please note, I am using .NET 2.0, coding with VB and my data is all held on a MySQL database.
This is pretty simple for most aspects, but as the whole thing is dynamic some things are proving more difficult.
I have a set of
tags which are dynamically generated with a repeater as follows:
<asp:Repeater runat="server" ID="locationRepeater">
<ItemTemplate>
<p id='locationNotification' title="<%# Container.DataItem %>" runat='server'>
COUNT DATA NEEDS TO GO HERE
</p>
<div class="jewelDescription" id="locationQuestionsNote" runat='server'>
Notification pending for <%# Container.DataItem %> <!-- (gives location name) -->
</div>
</ItemTemplate>
</asp:Repeater>
Currently, the Container.DataItem gives me the name of the location from a very simple dataBind of a list of location names
Dim locationList As Array = Split("1,2,3", ",")
locationRepeater.DataSource = locationList
locationRepeater.DataBind()
This is great, it allows locations to be added and removed from the system, the control panel is automatically updated depending on the number of locations currently in use.
HOWEVER... I've not got the actual data here, which should be a count of records from a separate Database table.
The data is really, really, simple, all I need to be able to do is query a table on my MySQL database for COUNT of ID WHERE locationName = Container.DataItem during each loop of the repeater... but I don't know how to do this.
I'm thinking maybe I have to do this first, create a table in memory somehow, but I am afraid I have no idea how to achieve this.
Has anyone got any examples of a similar thing, it's kind of binding to a repeater from two datasources... each task is very simple, but I don't know how to put it all together!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
中继器。 ItemDataBound
事件:You can use the
Repeater.ItemDataBound
event: