XML bind problem in a GridView ? [Resolved]

Posted by Akiii under C# on 7/11/2011 | Points: 10 | Views : 2171 | Status : [Member] | Replies : 10
Hi,
I am trying to update the page using AJAX but its not working. I have a Dropdownmenu . On selection of the item in the Dropdownmenu , i am trying to bind the values in a Repeater control . But i dont want any postback to occur so everything is inside the update panel.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="GenrePanel" runat="server">
<ContentTemplate>
<div class="columnheader">
Music News:
<asp:DropDownList ID="Genres" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Genres_SelectedIndexChanged">
<asp:ListItem Text="Rock" Value="RockFeed.xml" Selected="true" />
<asp:ListItem Text="Jazz" Value="JazzFeed.xml" />
<asp:ListItem Text="Blues" Value="BluesFeed.xml" />
</asp:DropDownList>
</div>
<asp:Repeater ID="GenreNews" runat="server" DataSourceID="GenreSource">
<ItemTemplate>
<div class="newshead">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#XPath("link") %>' Text='<%#XPath("title") %>' />
&nbsp;
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#XPath("link") %>' Text="[read more]" />
</div>
</ItemTemplate>
</asp:Repeater>
<hr />
Last Updated:
<%= DateTime.Now.ToLongTimeString() %>
<asp:XmlDataSource ID="GenreSource" runat="server" DataFile="RockFeed.xml"
XPath="RockFeed"></asp:XmlDataSource>
</ContentTemplate>
</asp:UpdatePanel>


The code behind file contains the following code:-

protected void Genres_SelectedIndexChanged(object sender,EventArgs e)
{
UpdateGenre();
}

private void UpdateGenre()
{
GenreSource.DataFile = Genres.SelectedValue;
GenreNews.DataBind();
}


I am depicting one of the xml file:-

<?xml version="1.0" encoding="utf-8" ?>
<RockFeed>
<option1>Rock1</option1>
<option2>Rock2</option2>
<option3>Rock3</option3>
<option4>Rock4</option4>
<option5>Rock5</option5>
</RockFeed>


please any help is appreciated..

Thanks and Regards
Akiii




Responses

Posted by: A4u_6178 on: 7/13/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hello Akiii,

The xml ur using is not formatted properly the xml file in ur case should look like as below ..
RockFeed.xml
<?xml version="1.0" encoding="utf-8" ?>

<parent>
<RockFeed>
<title>this is rockfeed source</title>
<description>hello... user feeds ur getting are from Rockfeed.. </description>
<readmore>[Read more]</readmore>
<link>http://www.dotnetfunda.com</link>
</RockFeed>
</parent>

JazzFeed.xml
<?xml version="1.0" encoding="utf-8" ?>

<parent>
<jazz>
<title>this is jazzfeed source</title>
<description>hello... user feeds ur getting are from Jazzfeed.. </description>
<readmore>[Read more]</readmore>
<link>http://www.dotnetfunda.com</link>
</jazz>
</parent>
BluesFeed.xml
<?xml version="1.0" encoding="utf-8" ?>

<parent>
<BluesFeed>
<title>this is Bluesfeed source</title>
<description>hello... user feeds ur getting are from Bluesfeed.. </description>
<readmore>[Read more]</readmore>
<link>http://www.dotnetfunda.com</link>
</BluesFeed>
</parent>

one more thing when ur using readmore as link then there should be some description prior to readmore link to do so add
<asp:Repeater ID="rptcontrol" runat="server" DataSourceID="XmlDataSource1">

<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#XPath("link") %>' Text='<%#XPath("title") %>' /><br />
<asp:Label ID="lbldesc" runat="server" Text='<%#XPath("description") %>'></asp:Label><br />
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#XPath("link") %>' Text="[read more]" />
</ItemTemplate>
</asp:Repeater>

xmldatasource:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/RockFeed.xml">

</asp:XmlDataSource>

The code behind looks like:
 protected void Genres_SelectedIndexChanged(object sender, EventArgs e)

{
XmlDataSource1.DataFile = "~/" + Genres.SelectedItem.Value;
}



Thanks & Regards,

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 7/11/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
What is not working Akiii? Looks like your XML is not formatted properly. You should not have Option1 Option2 etc. You should have only Option with different different values.

Look at this tutorials http://www.dotnetfunda.com/tutorials/controls/xmldatasource.aspx.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 7/11/2011 [Member] Bronze | Points: 25

Up
0
Down
Sir,
i want to select value in the dropdownlist and based i=on which data will be populated in the repeater control asynchronously. Thats why i have put everything in the updatepanel control.

but when i am selecting the the value in the dropdownlist, nothing shows up in the repeater control.....i dont know why ?

Please help me regarding this....!
(i have corrected the xml file)

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
HI Akiii,

I think, I have similar example which ur looking for pls find it in attacment, Here in this example i am consuming a xml webservice to get different category of news on my aspx page..
I hope u find it useful...
 Download source file

Thanks & Regards,

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 7/11/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi A4u_6178 ,

Thank you for the sample...
its an excellent example.....
Can you please help me regarding xml files.....?

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 7/11/2011 [Member] Starter | Points: 25

Up
0
Down
sure Akiii i try my best to help u..

Thanks & Regards,

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 7/11/2011 [Member] Bronze | Points: 25

Up
0
Down
Thanks....A4u_6178
Looking foward for help regarding xml file as data...!

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 7/13/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi Akiii,


Refer this,

http://www.dotnetfunda.com/codes/code1543-displaying-xml-data-in-datagrid-in-aspnet.aspx

Regards,
Susan

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 7/13/2011 [Member] Starter | Points: 25

Up
0
Down
Refer this


http://www.java2s.com/Code/ASP/Data-Binding/BindXMLdatatoaspgridviewC.htm

Thanks&Regards
LakshmiNarayana Nalluri.

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 7/14/2011 [Member] Bronze | Points: 25

Up
0
Down
@susan and @Lakn2 ......for providing me links....

@A4u_6178
Thanks for the explanation...
I mark yours as an answer...

Thanks and Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response