Just nu i M3-nätverket
Jump to content

ASP.NET.....flera kolumner i listbox


KarlGunnar

Recommended Posts

Jag har en vanlig listbox (ASP.NET och VB-kod) med en kolumn som visas enligt följande kod:

 

<%@ Page Language="vb" %> 
<%@ import Namespace="System.Data" %> 
<%@ import Namespace="System.Data.OleDb" %> 
<script runat="server"> 

   Dim intWdth, intID as integer 
   Dim strFornamn, strEfternamn as string 
   Sub Page_Load(Source as Object, E as EventArgs) 
           if not Page.IsPostBack then 
               BindData 
           End If 
   End Sub 

   Sub BindData() 
       Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("\dbSchema.mdb") & ";" 
       Dim sql as string = "SELECT * FROM Larare ORDER BY Efternamn" 
       Dim conn as New OleDbConnection(strConn) 
       Dim Cmd as New OleDbCommand(sql, conn) 
       Dim objDR as OleDbDataReader 
       conn.Open() 
       objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection) 
       list1.datasource=objDR 
       list1.DataValueField="ID" 
       list1.datatextfield="Efternamn" 
       list1.databind 
       list1.selectedindex=0 
       conn.Close() 

   End Sub 

 

Är det någon som vet hur man gör för att kunna visa ytterligare en kolumn i listboxen ex.vis kolumn "Fornamn"?

 

 

Link to comment
Share on other sites

  • 3 weeks later...

<%@ Page Language="vb" %> 
<%@ import Namespace="System.Data" %> 
<%@ import Namespace="System.Data.OleDb" %> 
<script runat="server"> 

Dim intWdth, intID as integer 
Dim strFornamn, strEfternamn as string 
Sub Page_Load(Source as Object, E as EventArgs) 
if not Page.IsPostBack then 
BindData 
End If 
End Sub 

Sub BindData() 
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("\dbSchema.mdb") & ";" 
Dim sql as string = "SELECT ID, Fornamn + Efternamn As Namn FROM Larare ORDER BY Efternamn" 
Dim conn as New OleDbConnection(strConn) 
Dim Cmd as New OleDbCommand(sql, conn) 
Dim objDR as OleDbDataReader 
conn.Open() 
objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseCon
nection) 
list1.datasource=objDR 
list1.DataValueField="ID" 
list1.datatextfield="Namn" 
list1.databind 
list1.selectedindex=0 
conn.Close() 

End Sub

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...