Jag har ett datagrid ed en edittemplate. I datagriden skriver jag ut hockeymatcher.
I databasen finns ett ja/nej fält som heter slutspel.
Om slutspel är true skulla jag vilja att en vanlig textbox skrivs ut. Om slutspel är false skulle jag vilja skriva ut en dropdownlist med några värden från en tabell i databasen.
Förkortat----
function funktionsomfixarbiffen(slutspel as string)
if slutspel = "ja" then
// returnera din listbox
else
// returnera din textbox
end if
end function
<edittemplate>
<%# funktionsomfixarbiffen(container.dataitem("slutspel"))%>
</edittemplate>
ska jag skapa textboxen och dropdownen i funktionen eller ska jag göra det på något annat sätt?
Du kan göra på båda sätten. Vill du inte skapa kontrollerna on-the-fly så kan du lägga upp båda kontrollerna och sedan i funktionen returnera huruvida de ska vara visible=true eller false.
andreas_lindh skrev:
Går det att fylla en dropdown med värden ifrån en databas inuti en funktion?
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 61: Dim dpllag_a As DropDownList = New DropDownList()
Line 62: Dim dpllag_b As DropDownList = New DropDownList()
Line 63: If slutspel = True Then
Line 64: tblag_a.Visible = True
Line 65: tblag_b.Visible = True
Source File: h:\inetpub\wwwroot\cup\spelschema.aspx.vb Line: 63
Funktionen
Public Shared Function kolla(ByVal slutspel As String)
Dim tblag_a As TextBox = New TextBox()
Dim tblag_b As TextBox = New TextBox()
Dim dpllag_a As DropDownList = New DropDownList()
Dim dpllag_b As DropDownList = New DropDownList()
If slutspel = True Then
tblag_a.Visible = True
tblag_b.Visible = True
Else
dpllag_a.Visible = True
dpllag_b.Visible = True
End If
End Function
Exception Details: System.FormatException: String was not recognized as a valid Boolean.
Source Error:
Line 62: Dim dpllag_b As DropDownList = New DropDownList()
Line 63: Dim temp As Boolean
Line 64: temp = Convert.ToBoolean(slutspel)
Line 65: If temp = True Then
Line 66: tblag_a.Visible = True
Source File: h:\inetpub\wwwroot\cup\spelschema.aspx.vb Line: 64