Put Data in DropDownList

Discussion in 'ASP .Net' started by ruca, Feb 6, 2004.

  1. ruca

    ruca Guest

    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????????????????


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

    ruca
     
    ruca, Feb 6, 2004
    #1
    1. Advertising

  2. 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
     
    =?Utf-8?B?VGltIFN0YWxs?=, Feb 6, 2004
    #2
    1. Advertising

  3. 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>


    "ruca" <> wrote in message
    news:uZqK$...
    > 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????????????????
    >
    >
    > --
    > Thanks (if you help me)
    > Hope this helps (if I help you)
    >
    > ruca
    >
    >
     
    William LaMartin, Feb 6, 2004
    #3
  4. ruca

    Jim Hughes Guest

    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.

    "William LaMartin" <> wrote in message
    news:u8$...
    > 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>
    >
    >
    > "ruca" <> wrote in message
    > news:uZqK$...
    > > 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????????????????
    > >
    > >
    > > --
    > > Thanks (if you help me)
    > > Hope this helps (if I help you)
    > >
    > > ruca
    > >
    > >

    >
    >
     
    Jim Hughes, Feb 7, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. COHENMARVIN
    Replies:
    2
    Views:
    518
    cdmlb
    Sep 20, 2006
  2. mr2_93
    Replies:
    1
    Views:
    3,602
    mr2_93
    Oct 2, 2005
  3. Bart
    Replies:
    4
    Views:
    343
  4. Vincent
    Replies:
    3
    Views:
    931
    Vincent
    Mar 7, 2008
  5. Gabriel Rossetti
    Replies:
    3
    Views:
    555
    Jerry Hill
    Apr 25, 2008
Loading...

Share This Page