XML Dropdownlist- Custom DataTextField

Discussion in 'ASP .Net Web Controls' started by Darrin, Jun 22, 2006.

  1. Darrin

    Darrin Guest

    I currently have some code that sends some XML to the USPS website and
    returns some XML with shipping costs. I am reading the XML and then binding
    it to a dropdownlist. However, I would like to bind two of the XML nodes
    (MailService & Rate) as the datatextfield. This way the user will be able to
    see the mail service type (standard, prority, etc.) and the rate ($8.00,
    $6.00, etc.) Currently I am only able to use one of the XML nodes to bind it
    to the drop down list. Does anyone have a sample that would allow me to add
    more than one data text field?


    XML That is being returned:-----------------------------
    <?xml version="1.0" ?>

    <RateV2Response>

    <Package ID="0">

    <ZipOrigination>10022</ZipOrigination>

    <ZipDestination>20008</ZipDestination>

    <Pounds>10</Pounds>

    <Ounces>5</Ounces>

    <Container>Flat Rate Box</Container>

    <Size>REGULAR</Size>

    <Zone>3</Zone>

    <Postage>

    <MailService>Priority Mail Flat Rate Box (11.25" x 8.75" x 6")</MailService>

    <Rate>7.70</Rate>

    </Postage>

    <Postage>

    <MailService>Priority Mail Flat Rate Box (14" x 12" x 3.5")</MailService>

    <Rate>7.70</Rate>

    </Postage>

    </Package>

    </RateV2Response>


    CODE TO GET XML AND BIND TO DropdownList
    --------------------------------------------------------

    "strResponseXML"- returned XML as listed above

    xmlreader = New XmlTextReader(strResponseXML, XmlNodeType.Document, Nothing)

    xmlreader.Read()

    Dim ds As New DataSet
    ds.ReadXml(xmlreader)

    DropDownList1.DataMember = "Postage"
    DropDownList1.DataValueField = "Rate"
    DropDownList1.DataTextField = "MailService" ''(This is were I would like to
    add the Rate value as well.)

    DropDownList1.DataSource = ds
    DropDownList1.DataBind()


    THIS IS WHAT IS CURRENTLY IN THE DROPDOWN
    -----------------------------------------------------------
    Priority Mail Flat Rate Box (11.25" x 8.75" x 6")
    Priority Mail Flat Rate Box (14" x 12" x 3.5")


    THIS IS WHAT I AM LOOKING FOR
    ----------------------------------------------
    Priority Mail Flat Rate Box (11.25" x 8.75" x 6") - $7.70
    Priority Mail Flat Rate Box (14" x 12" x 3.5") - $7.70
     
    Darrin, Jun 22, 2006
    #1
    1. Advertising

  2. You might try adding a datacolumn, whose value is calculated by an
    expression, to the table that was created after you executed this line:
    ds.ReadXml(xmlreader)

    http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Darrin" wrote:

    > I currently have some code that sends some XML to the USPS website and
    > returns some XML with shipping costs. I am reading the XML and then binding
    > it to a dropdownlist. However, I would like to bind two of the XML nodes
    > (MailService & Rate) as the datatextfield. This way the user will be able to
    > see the mail service type (standard, prority, etc.) and the rate ($8.00,
    > $6.00, etc.) Currently I am only able to use one of the XML nodes to bind it
    > to the drop down list. Does anyone have a sample that would allow me to add
    > more than one data text field?
    >
    >
    > XML That is being returned:-----------------------------
    > <?xml version="1.0" ?>
    >
    > <RateV2Response>
    >
    > <Package ID="0">
    >
    > <ZipOrigination>10022</ZipOrigination>
    >
    > <ZipDestination>20008</ZipDestination>
    >
    > <Pounds>10</Pounds>
    >
    > <Ounces>5</Ounces>
    >
    > <Container>Flat Rate Box</Container>
    >
    > <Size>REGULAR</Size>
    >
    > <Zone>3</Zone>
    >
    > <Postage>
    >
    > <MailService>Priority Mail Flat Rate Box (11.25" x 8.75" x 6")</MailService>
    >
    > <Rate>7.70</Rate>
    >
    > </Postage>
    >
    > <Postage>
    >
    > <MailService>Priority Mail Flat Rate Box (14" x 12" x 3.5")</MailService>
    >
    > <Rate>7.70</Rate>
    >
    > </Postage>
    >
    > </Package>
    >
    > </RateV2Response>
    >
    >
    > CODE TO GET XML AND BIND TO DropdownList
    > --------------------------------------------------------
    >
    > "strResponseXML"- returned XML as listed above
    >
    > xmlreader = New XmlTextReader(strResponseXML, XmlNodeType.Document, Nothing)
    >
    > xmlreader.Read()
    >
    > Dim ds As New DataSet
    > ds.ReadXml(xmlreader)
    >
    > DropDownList1.DataMember = "Postage"
    > DropDownList1.DataValueField = "Rate"
    > DropDownList1.DataTextField = "MailService" ''(This is were I would like to
    > add the Rate value as well.)
    >
    > DropDownList1.DataSource = ds
    > DropDownList1.DataBind()
    >
    >
    > THIS IS WHAT IS CURRENTLY IN THE DROPDOWN
    > -----------------------------------------------------------
    > Priority Mail Flat Rate Box (11.25" x 8.75" x 6")
    > Priority Mail Flat Rate Box (14" x 12" x 3.5")
    >
    >
    > THIS IS WHAT I AM LOOKING FOR
    > ----------------------------------------------
    > Priority Mail Flat Rate Box (11.25" x 8.75" x 6") - $7.70
    > Priority Mail Flat Rate Box (14" x 12" x 3.5") - $7.70
    >
    >
    >
    >
     
    Phillip Williams, Jun 22, 2006
    #2
    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. Parodi Development
    Replies:
    0
    Views:
    3,719
    Parodi Development
    Sep 10, 2004
  2. nicholas
    Replies:
    5
    Views:
    15,788
    nicholas
    Dec 3, 2004
  3. Sam
    Replies:
    1
    Views:
    12,129
    Eliyahu Goldin
    Feb 18, 2005
  4. jobs
    Replies:
    0
    Views:
    502
  5. Mark Rae
    Replies:
    5
    Views:
    5,426
    Mark Rae
    Jan 12, 2007
Loading...

Share This Page