apchambers
Programmer
I want to make one call to the database to populate multiple dropdownlists in gridview template fields. I have tried populating hashtables, datasets etc but I can't work out how to make one call to the database.
This code currently works but is very slow
<asp:TemplateField HeaderText="Player 1" SortExpression="lngCDPL1ID" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate>
<aspropDownList ID="lngCDPL1IDEdit" runat="server" DataSource='<%# GetPlayerds() %>' Text='<%# Bind("lngCDPL1ID") %>'
DataTextField="txtPLName" DataValueField="lngPLID" AutoPostBack="false" >
</aspropDownList>
</ItemTemplate>
Public Function GetPlayerds() As DataSet
Dim CurrConn As New SqlClient.SqlConnection
Dim myConn As New GetConnection
CurrConn.ConnectionString = myConn.GetMyConnection
Dim mystr As String = "SELECT tblPlayers.lngPLID, dbo.fnPlayerName(txtPLFirstName,txtPLLastName,lngPLDeleted) as txtPLName from tblPlayers" & _
" where(tblPlayers.lngPLVisitor = 0 Or tblPlayers.lngPLID = 0)" & _
" order by lngPLDeleted, txtPLFirstName, txtPLLastName"
Dim ds As New DataSet
Dim ad As New SqlDataAdapter(mystr, CurrConn)
ad.Fill(ds, "Players")
Return ds
End Function
This code currently works but is very slow
<asp:TemplateField HeaderText="Player 1" SortExpression="lngCDPL1ID" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate>
<aspropDownList ID="lngCDPL1IDEdit" runat="server" DataSource='<%# GetPlayerds() %>' Text='<%# Bind("lngCDPL1ID") %>'
DataTextField="txtPLName" DataValueField="lngPLID" AutoPostBack="false" >
</aspropDownList>
</ItemTemplate>
Public Function GetPlayerds() As DataSet
Dim CurrConn As New SqlClient.SqlConnection
Dim myConn As New GetConnection
CurrConn.ConnectionString = myConn.GetMyConnection
Dim mystr As String = "SELECT tblPlayers.lngPLID, dbo.fnPlayerName(txtPLFirstName,txtPLLastName,lngPLDeleted) as txtPLName from tblPlayers" & _
" where(tblPlayers.lngPLVisitor = 0 Or tblPlayers.lngPLID = 0)" & _
" order by lngPLDeleted, txtPLFirstName, txtPLLastName"
Dim ds As New DataSet
Dim ad As New SqlDataAdapter(mystr, CurrConn)
ad.Fill(ds, "Players")
Return ds
End Function