在 vb.net 的数据读取器中添加数据集
我希望我正确地提出了问题标题。让我解释一下我的问题 - 我正在通过 vb.net 代码(htmltablecell、htmltablerow..)制作一个表,没有这个表填充 SQL 查询并且工作完美。但在这个表的一个表单元格中,我需要添加一个下拉列表,该列表需要完全不同的查询,并且应在每一行上单独运行。所以代码如下
Sql = "..." rd = ExecuteReader(SqlCnn, Sql)
Dim newcounter As Integer = 0
While rd.Read()
newcounter += 1
Dim tr As New HtmlTableRow
Dim td As New HtmlTableCell
Dim chkbox As New CheckBox
Dim id As String = rd("id") & ""
If id.Length = 0 Then id = "new" & newcounter
id &= "_" & rd("col1")
chkbox.Style.Add("width", "20%")
chkbox.ID = "new_id_" & id
chkbox.Text = rd("col1")
tr.Style.Add("width", "100%")
td.Style.Add("width", "10%")
td.Style.Add("text-align", "left")
td.Controls.Add(chkbox)
tr.Cells.Add(td)
td = New HtmlTableCell
td.Style.Add("width", "30%")
Dim ddl As New dropdownlist
ddl.Style.Add("width", "80%")
ddl.ID = "a1_" & id
--???????
td.Controls.Add(ddl)
tr.Cells.Add(td)
???在代码中,下拉列表每次都应使用自己的数据读取器以及 while 循环和查询进行填充。我怎样才能做到这一点?
i hope i have asked the question title correctly. let me explain my issue -
i am making a table through vb.net code (htmltablecell, htmltablerow..) no this table populates with an sql query and works perfectly. but inside this table in one tablecell, i need to add a dropdownlist which shall require a completely differernt query and shall run on its own on each row. so the code is as follows
Sql = "..."
rd = ExecuteReader(SqlCnn, Sql)
Dim newcounter As Integer = 0
While rd.Read()
newcounter += 1
Dim tr As New HtmlTableRow
Dim td As New HtmlTableCell
Dim chkbox As New CheckBox
Dim id As String = rd("id") & ""
If id.Length = 0 Then id = "new" & newcounter
id &= "_" & rd("col1")
chkbox.Style.Add("width", "20%")
chkbox.ID = "new_id_" & id
chkbox.Text = rd("col1")
tr.Style.Add("width", "100%")
td.Style.Add("width", "10%")
td.Style.Add("text-align", "left")
td.Controls.Add(chkbox)
tr.Cells.Add(td)
td = New HtmlTableCell
td.Style.Add("width", "30%")
Dim ddl As New dropdownlist
ddl.Style.Add("width", "80%")
ddl.ID = "a1_" & id
--???????
td.Controls.Add(ddl)
tr.Cells.Add(td)
the ??? in the code is where the dropdownlist shall get populated each time with its own datareader and while loop and query. how can i achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会通过两个查询来完成此操作; 1 获取 ddl 数据,1 获取实际记录。在实际结果之前获取ddl数据(ddlDataReader),创建ddl对象并将其添加到每一行。
像这样的东西应该可以工作:(我不做VB.Net,所以你可能需要修复一些东西)
另一种方法是将ddl数据加载到数据表中,这样你就可以多次循环它,然后创建创建每一行时具有唯一 ID 的 ddl。
I would do this with 2 queries; 1 to get the ddl data and 1 to get the actual records. Get the ddl data (ddlDataReader) before the actual results, create the ddl object and add it to each row.
Something like this should work: (I don't do VB.Net, so you may need to fix things)
Another approach would be to load the ddl data into a datatable, so that you can loop through it multiple times, and then create the ddl with a unique Id when each row is being created.