FormView

  • Thread starter Thread starter Miro
  • Start date Start date
M

Miro

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
 
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! |
*******************************************
 
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 witha
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 extractmy
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.
 
Thank you,

XQuery did the trick

Cheers'

Miro

Gregory A. Beamer said:
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! |
*******************************************
 
Back
Top