0
我试图做一些相当简单的事情,但由于某种原因,某些事情出错了,我不能为我的生活看到为什么。ASP.Net Gridview对于RowDataBound内的下一个循环
我有一个数据网格,RowDataBound我想循环通过另一个数据集,并显示一个单元格内的多个值。
所以我下面的基本代码循环访问gridview RowDataBound中的数据集,我在循环中设置i = 0,然后我只是写出数据集中字段的值和i的值问题是第一行在网格的每一行中写入i = 1的值,因此它从不写出数据集中的第一行,是否有人知道为什么会出现这种情况?
变量i不在其他地方使用,所以不能从某处获取值。
Protected Sub gvReport_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvReport.RowDataBound
Dim cmdAgent As SqlCommand = New SqlCommand()
cmdAgent.Connection = PgsSQL
cmdAgent.CommandText = "spClientEstateAgent"
cmdAgent.CommandType = CommandType.StoredProcedure
Dim pCaseIdb As SqlParameter
pCaseIdb = New SqlParameter()
pCaseIdb.ParameterName = "@CaseId"
pCaseIdb.SqlDbType = SqlDbType.Int
pCaseIdb.Direction = ParameterDirection.Input
pCaseIdb.Value = Trim(CaseId)
cmdAgent.Parameters.Add(pCaseIdb)
'data adapter
Dim daAgent As SqlDataAdapter = New SqlDataAdapter
daAgent.SelectCommand = cmdAgent
'data set
Dim dsAgent As DataSet = New DataSet()
daAgent.Fill(dsAgent, "Agent")
cmdAgent.Dispose()
PgsSQL.Close()
Dim AgentCount As Integer = dsAgent.Tables(0).Rows.Count
For i As Integer = 0 To AgentCount - 1
lAgents.Text = dsAgent.Tables("Agent").Rows(i).Item("Name") & " : " & i
Next
End Sub
由于提前, J.