我想使用下面的代码在表中显示查询结果。
我的问题是在第DataGrid
2 行显示了第 1 行和第 2 行的查询结果。同样在第 3 行显示第 2 行和第 3 行的结果,依此类推。
有人能告诉我如何在 DataGrid 的第 2 行中仅显示第 2 行的查询等吗?
有没有办法在一行被填满后清除表格?
For Each d In DataGrid1.Items
htbl = d.FindControl("Table1")
sql = "select username, count(*) as cnt from elexa where r_id='" & d.Cells.Item(0).Text & "' group by username order by cnt desc"
cmd = New SqlCommand(sql, conn)
adp=new SqlDataAdapter(cmd)
adp.Fill(ds,"elexa")
tbl = ds.Tables("elexa")
tbl = ds.Tables("elexa")
cnt = tbl.Rows.Count
For i = 0 To cnt - 3
Dim hRw As New HtmlTableRow
Dim hRw2 As New HtmlTableRow
For j = 0 To 2
Dim hCll As New HtmlTableCell
Dim hcll2 As New HtmlTableCell
hCll.InnerHtml ="<font size=2>" & ds.Tables("elexa").Rows(i).Item("username") & "</font>"
hRw.Controls.Add(hCll)
i = i + 1
hCll = New HtmlTableCell
Next j
htbl.Controls.Add(hRw)
hRw2.BgColor = "silver"
hRw2.Height = "1px"
Next
Next d