Put Data in DropDownList

R

ruca

I have this in code:
I'm reading data from a .TXT file
----------------------------------------------------
Sub ProcessUser(txtLine)
On Error Resume Next

Dim p1, pos as Integer
Dim Cd, LineAux, NomeFunc, Pass, strLabel as String
Dim row as DataRow

p1 = instr(txtLine,",")
if p1>0 then
Cd=left(txtLine,p1-1)
LineAux = mid(txtLine,p1+1)
pos = instr(LineAux,",")
NomeFunc = left(LineAux,pos-1)
Pass = mid(LineAux, pos+1)
'Response.Write CdFunc & "-" & NomeFunc & "-" & Pass
strLabel="CdRcs = "& "'" & Cd & "'"
response.write(Cd)

row = table.NewRow()
row("CdRcs") = Cd
row("NmAbreviado") = NomeFunc
row("Key") = Pass

table.Rows.Add(row)

end if
End Sub

Function ler_users() As DataTable
On Error Resume Next
Dim objFicheiro, LerUser as Object

objFicheiro = CreateObject("Scripting.fileSystemObject")
LerUser = objFicheiro_OpenTextFile(Server.MapPath("func.txt"))

While not LerUser.AtEndOfStream
ProcessUser (LerUser.ReadLine)
End While

LerUser.Close
LerUser = nothing

return table
End Function
---------------------------------------------

I want to put in a dropdownlist the name of people but I can't. For that I
have this:

asp:DropDownList id="cxFunc" runat="server" DataSource="<% # ler_users() %>"
DataTextField="NmAbreviado" DataMember="CdRcs" DataValueField="CdRcs"


Can you help me??? How can I put data in the dropdownlist????????????????
 
G

Guest

Hello
A couple ways
(1) You could databind it. Set the dropdowns.DataSource, DatatextField="SomeColumnName", and DataValueField="SomeColumnName", and then .DataBind(

(2) You could add to the items collection: Dropdown.Items.Add( ), or .AddAt(...

HTH
Tim Stal

----- ruca wrote: ----

I have this in code
I'm reading data from a .TXT fil
---------------------------------------------------
Sub ProcessUser(txtLine
On Error Resume Nex

Dim p1, pos as Intege
Dim Cd, LineAux, NomeFunc, Pass, strLabel as Strin
Dim row as DataRo

p1 = instr(txtLine,","
if p1>0 the
Cd=left(txtLine,p1-1
LineAux = mid(txtLine,p1+1
pos = instr(LineAux,","
NomeFunc = left(LineAux,pos-1
Pass = mid(LineAux, pos+1
'Response.Write CdFunc & "-" & NomeFunc & "-" & Pas
strLabel="CdRcs = "& "'" & Cd & "'
response.write(Cd

row = table.NewRow(
row("CdRcs") = C
row("NmAbreviado") = NomeFun
row("Key") = Pas

table.Rows.Add(row

end i
End Su

Function ler_users() As DataTabl
On Error Resume Nex
Dim objFicheiro, LerUser as Objec

objFicheiro = CreateObject("Scripting.fileSystemObject"
LerUser = objFicheiro_OpenTextFile(Server.MapPath("func.txt")

While not LerUser.AtEndOfStrea
ProcessUser (LerUser.ReadLine
End Whil

LerUser.Clos
LerUser = nothin

return tabl
End Functio
--------------------------------------------

I want to put in a dropdownlist the name of people but I can't. For that
have this

asp:DropDownList id="cxFunc" runat="server" DataSource="<% # ler_users() %>
DataTextField="NmAbreviado" DataMember="CdRcs" DataValueField="CdRcs


Can you help me??? How can I put data in the dropdownlist???????????????


-
Thanks (if you help me
Hope this helps (if I help you

ruc
 
W

William LaMartin

Here is how I populate a dropDownList with the US state abbreviations:

Protected ds As New DataSet

in the page load event|:

ds.Clear()
Protected ds As New DataSet
ds.ReadXml(Server.MapPath(".") & "\states.xml")
Me.DropDownStateList.DataSource = ds
Me.DropDownStateList.DataTextField = "Field1"
Me.DropDownStateList.DataBind()

And here is the structure of the xml file:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:eek:d="urn:schemas-microsoft-com:eek:fficedata">
<States>
<Field1>AK</Field1>
</States>
<States>
<Field1>AL</Field1>
</States>
........
........
<States>
<Field1>WY</Field1>
</States>
</dataroot>
 
J

Jim Hughes

You should be able to replace

ds.ReadXml(Server.MapPath(".") & "\states.xml")

with

ds.ReadXml(Server.MapPath("states.xml"))

The . (Current Directory) would be assumed in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top