添加行时重新绑定gridview会增加重新绑定已绑定行的开销

时间:2013-06-20 11:40:43

标签: vb.net gridview rowdatabound

我有一个包含DropDownList的GridView,我在RowBoundEvent中使用DB查询填充DDL。

Grid的其余列是BoundFields,它们是从(Object)列表中填充的。

每次我向GridView添加一个新行时,我必须再次查询数据库中以前填充的DDL这个我想避免,任何sugestions?

编辑:添加代码

 <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

我认为这是相关的代码。

0 个答案:

没有答案