FormView

Discussion in 'ASP .Net' started by Miro, Oct 26, 2009.

  1. Miro

    Miro Guest

    I am having a hard time understanding "Labels" within asp.net and
    databinding.

    I have a very simple xml file and I dropped an XMLDatasource onto the aspx
    page.
    Each "Node" has 3 dataparts...
    <types>
    <type id="1" desc="hello" age="12" />
    <type id="2" desc="goodbye" age="33" />
    </types>

    I linked a combo box to the XMLDatasource
    (Combo box displays all the proper available "Descriptions".
    All works well... I have the value = id and the list is displaying the desc

    Now, on the DropDownList1_SelectedIndexChanged i want to put code to update
    a label on the aspx page with the 'Age' of the current id on the selected
    item in the drop down list.

    Here I am stumped.

    I think I am a lot closer... I have a formview with an Item Template with a
    label bound to the "Age" column.
    But how do i change the Formview to be the record ID hit within the dropdown
    list.

    The dropdown list is "Outside" of the FormView so somehow I need to either
    "Seek" the proper xmlDatarecord and make the formview link to that,
    or get rid of the formview and just add Labels...and when I seek the record
    ( somehow ) on the dropdown list, I can just say
    lblAge.text = bla

    I do not know how to "seek" the xmldatafile as a datarow so I can extract my
    columns or something.

    Thanks,

    Miro
     
    Miro, Oct 26, 2009
    #1
    1. Advertising

  2. "Miro" <> wrote in
    news:#fjp#:

    >
    > I do not know how to "seek" the xmldatafile as a datarow so I can
    > extract my columns or something.


    LINQ to XML would be my first option, as it is easier to use than a
    "traditional" XML approach. XPath or XQuery is the other route.

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Oct 26, 2009
    #2
    1. Advertising

  3. On Oct 26, 4:26 pm, "Miro" <> wrote:
    > I am having a hard time understanding "Labels" within asp.net and
    > databinding.
    >
    > I have a very simple xml file and I dropped an XMLDatasource onto the aspx
    > page.
    > Each "Node" has 3 dataparts...
    > <types>
    > <type id="1" desc="hello" age="12" />
    > <type id="2" desc="goodbye" age="33" />
    > </types>
    >
    > I linked a combo box to the XMLDatasource
    > (Combo box displays all the proper available "Descriptions".
    > All works well... I have the value = id and the list is displaying the desc
    >
    > Now, on the DropDownList1_SelectedIndexChanged i want to put code to update
    > a label on the aspx page with the 'Age' of the current id on the selected
    > item in the drop down list.
    >
    > Here I am stumped.
    >
    > I think I am a lot closer... I have a formview with an Item Template with a
    > label bound to the "Age" column.
    > But how do i change the Formview to be the record ID hit within the dropdown
    > list.
    >
    > The dropdown list is "Outside" of the FormView so somehow I need to either
    > "Seek" the proper xmlDatarecord and make the formview link to that,
    > or get rid of the formview and just add Labels...and when I seek the record
    > ( somehow ) on the dropdown list, I can just say
    > lblAge.text = bla
    >
    > I do not know how to "seek" the xmldatafile as a datarow so I can extract my
    > columns or something.
    >
    > Thanks,
    >
    > Miro


    Following the same logic, you may add another XmlDataSource (e.g.
    XmlDataSource2) and set

    protected void DropDownList1_SelectedIndexChanged (...)
    {

    XmlDataSource2.Xpath = "/type[@id='" + DropDownList1.SelectedValue +
    "']";

    }

    then your FormView could have something like this

    <asp:FormView ... DataSourceID="XmlDataSource2">
    <ItemTemplate>
    <asp:Label ... Text='<%# XPath("@age") %>'
    </ItemTemplate>
    </asp:FormView>

    I did not test it, but I think it should work in that way.

    Hope this helps.
     
    Alexey Smirnov, Oct 26, 2009
    #3
  4. Miro

    Miro Guest

    Thank you,

    XQuery did the trick

    Cheers'

    Miro

    "Gregory A. Beamer" <> wrote in message
    news:Xns9CB077F18E3D5gbworld@207.46.248.16...
    > "Miro" <> wrote in
    > news:#fjp#:
    >
    >>
    >> I do not know how to "seek" the xmldatafile as a datarow so I can
    >> extract my columns or something.

    >
    > LINQ to XML would be my first option, as it is easier to use than a
    > "traditional" XML approach. XPath or XQuery is the other route.
    >
    > Peace and Grace,
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
     
    Miro, Oct 27, 2009
    #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. =?Utf-8?B?c2NrMTA=?=

    FormView Control

    =?Utf-8?B?c2NrMTA=?=, Oct 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,034
    Steven Cheng[MSFT]
    Oct 18, 2004
  2. CJ Taylor

    2.0 Formview question

    CJ Taylor, Oct 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,436
    Jon Stranger
    Oct 10, 2004
  3. Juan Irigoyen

    FormView in ASP 2.0

    Juan Irigoyen, Oct 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    361
    Juan Irigoyen
    Oct 6, 2004
  4. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    586
    Chris
    May 19, 2007
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    714
    David Thielen
    Jun 16, 2006
Loading...

Share This Page