0

I have a GridView that contains a DropDownList and I populate the DDL with a DB query in the RowBoundEvent.

The rest of the columns of the Grid are BoundFields and they are populated from a list of ( Object ) .

Every time I add a new Row to the GridView I have to query again the DB for previously populated DDLs This I want to avoid, any sugestions?

Edit: added code

 <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

This is the relevant code, I think.

UrsulRosu
  • 507
  • 1
  • 6
  • 16

0 Answers0