Hi there,
I'm using linq to query XML and bind to RadGrid.
Here is the test XML:
My aspx page:
My code behind in NeedDataSource
It came no result, but if I remove Item template, change AutoGenerateColumns to true, it display the two records. It looks like the data is not binded to item template correctly. I also tried <%# Bind("Size") %>, but it doesn't work, what is the correct way to bind data column?
I'm using telerik.Web.UI for .Net 3.5.
Could you please help? Thanks.
I'm using linq to query XML and bind to RadGrid.
Here is the test XML:
<
Results
>
<
Result
>
<
Url
>Url 2</
Url
>
<
Title
>Title 1</
Title
>
<
FileExtension
>PPT</
FileExtension
>
<
Description
>Desc 1</
Description
>
<
Size
>36KB</
Size
>
<
Author
>L1, F1</
Author
>
<
WriteDate
>2010-04-29</
WriteDate
>
<
Rank
>881</
Rank
>
</
Result
>
<
Result
>
<
Url
>Url 1</
Url
>
<
Title
>Title 2</
Title
>
<
FileExtension
>PPT</
FileExtension
>
<
Description
>Desc 2</
Description
>
<
Size
>72KB</
Size
>
<
Author
>L2, F2</
Author
>
<
WriteDate
>2010-04-30</
WriteDate
>
<
Rank
>825</
Rank
>
</
Result
>
</
Results
>
My aspx page:
<
telerik:RadGrid
ID
=
"RadGrid1"
Width
=
"97%"
AutoGenerateColumns
=
"false"
AllowPaging
=
"True"
PageSize
=
"15"
runat
=
"server"
AllowSorting
=
"True"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
GridLines
=
"None"
>
<
MasterTableView
Width
=
"100%"
>
<
ItemTemplate
>
<
div
>
<
span
>
<
asp:HyperLink
runat
=
"server"
ID
=
"lnkResultUrl"
NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "Url")%> '
Text='<%#DataBinder.Eval(Container.DataItem, "Title")%> ' />
<
br
/>
</
span
>
<
div
>
<
asp:Label
runat
=
"server"
ID
=
"lblResultSummay1"
Text='<%#DataBinder.Eval(Container.DataItem, "Description")%> '></
asp:Label
>
<
br
/>
</
div
>
<
p
>
<
span
>
<
asp:HyperLink
runat
=
"server"
ID
=
"lnkResult"
NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "Url")%> '
Text='<%#DataBinder.Eval(Container.DataItem, "Url")%> ' />
</
span
>
-
<
asp:Label
runat
=
"server"
ID
=
"Label1"
Text='<%#DataBinder.Eval(Container.DataItem, "Size")%> '></
asp:Label
>
-
<
asp:Label
runat
=
"server"
ID
=
"Label2"
Text='<%#DataBinder.Eval(Container.DataItem, "Author")%> '></
asp:Label
>
-
<
asp:Label
runat
=
"server"
ID
=
"Label3"
Text='<%#DataBinder.Eval(Container.DataItem, "WriteDate")%> '></
asp:Label
>
<
br
/>
</
p
>
</
div
>
</
ItemTemplate
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
PagerTextFormat
=
"Change page: {4} | Displaying page {0} of {1}, items {2} to {3} of {5}"
/>
<
FilterMenu
EnableTheming
=
"True"
>
<
CollapseAnimation
Duration
=
"200"
Type
=
"OutQuint"
/>
</
FilterMenu
>
</
telerik:RadGrid
>
My code behind in NeedDataSource
XElement xe= XElement.Parse(@"<
Results
>
<
Result
>
<
Url
>Url 2</
Url
>
<
Title
>Title 1</
Title
>
<
FileExtension
>PPT</
FileExtension
>
<
Description
>Desc 1</
Description
>
<
Size
>36KB</
Size
>
<
Author
>L1, F1</
Author
>
<
WriteDate
>2010-04-29</
WriteDate
>
<
Rank
>881</
Rank
>
</
Result
>
<
Result
>
<
Url
>Url 1</
Url
>
<
Title
>Title 2</
Title
>
<
FileExtension
>PPT</
FileExtension
>
<
Description
>Desc 2</
Description
>
<
Size
>72KB</
Size
>
<
Author
>L2, F2</
Author
>
<
WriteDate
>2010-04-30</
WriteDate
>
<
Rank
>825</
Rank
>
</
Result
>
</
Results
>");
var xTest = from xItem in xe.Elements("Result")
select new
{
Url = xItem.Element("Url").Value,
Title = xItem.Element("Title").Value,
FileExtension = xItem.Element("FileExtension").Value,
Description = xItem.Element("Description").Value,
Size = xItem.Element("Size").Value,
Author = xItem.Element("Author").Value,
WriteDate = xItem.Element("WriteDate").Value,
Rank = xItem.Element("Rank").Value
};
RadGrid1.DataSource = xTest;
It came no result, but if I remove Item template, change AutoGenerateColumns to true, it display the two records. It looks like the data is not binded to item template correctly. I also tried <%# Bind("Size") %>, but it doesn't work, what is the correct way to bind data column?
I'm using telerik.Web.UI for .Net 3.5.
Could you please help? Thanks.