我有一个包含 DropDownList 的 GridView,并在 RowBoundEvent 中使用 DB 查询填充 DDL。
Grid 的其余列是 BoundFields,它们是从 (Object) 的列表中填充的。
每次我向 GridView 添加新行时,我都必须再次查询数据库以查找以前填充的 DDL 这我想避免,有什么建议吗?
编辑:添加代码
<asp:BoundField DataField="getUserName" HeaderText="Name" />
<asp:BoundField DataField="getUserId" HeaderText="User ID" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlRoles" runat="server" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Grid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles addUsersGrid.RowDataBound
Dim ddl As DropDownList = TryCast(e.Row.FindControl("ddlRoles"), DropDownList)
If ddl IsNot Nothing Then
Dim sSQL As String = "SELECT ..."
Dim rolesAdapter As OdbcDataAdapter = New OdbcDataAdapter(sSQL, ADOCon)
rolesAdapter.Fill(dt)
For Each dr As DataRow In dt.Rows
ddl.Items.Add(dr("NAME").ToString())
ddl.Items(iInt).Value = dr("ID").ToString
iInt += 1
Next
end if
这是相关的代码,我想。