Hey!
The list displays message text and has 2 buttons "+" and "-", so users vote if they like or dislike the message.
I tried 2 solutions but have problems with both.
1st solution is without needdatasource:
Here is the ListView:
I databind the list in page_load;
Everything works fine on the first page, the itemcommand fires, tweet is set properly... However if I use the pager the ItemCommand doesn't even fire.
The second solution is with using the needdatasource:
ListIs the same except for needdatasource event, itemcommand is the same, the itemcommand fires everywhere now except that the item.DataItem is always null...
I removed the databinding from the page load and added it to the needdata source. I feel like I have to call the list's DataBind function somewhere, but I don't know here...
this is what i do in needdatasource:
Thanks for you help!
Sincerely, Jure
The list displays message text and has 2 buttons "+" and "-", so users vote if they like or dislike the message.
I tried 2 solutions but have problems with both.
1st solution is without needdatasource:
Here is the ListView:
<telerik:RadListView ID="rlvTweets" runat="server" Width="100%" DataKeyNames="Tweet_ID" AllowPaging="True" PageSize="5" ItemPlaceholderID="ObjectHolder" OnItemCommand="rlvTweets_ItemCommand" OnItemDataBound="rlvTweets_ItemDataBound" > <LayoutTemplate> <asp:Panel ID="ObjectHolder" runat="server" /> <telerik:RadDataPager ID="rdpTweets" runat="server" PagedControlID="rlvTweets" PageSize="5" Visible='<%# rlvTweets.PageCount != 1%>' > <Fields> <telerik:RadDataPagerButtonField FieldType="Numeric" /> </Fields> </telerik:RadDataPager> </LayoutTemplate> <ItemSeparatorTemplate> <div class="separator"></div> </ItemSeparatorTemplate> <ItemTemplate> <%--Image Avatar--%> <asp:HyperLink ID="hlAvatar" runat="server" ImageUrl='<%#Eval("trTwitterUser.Avatar")%>' /> <%--Link Username--%> <asp:HyperLink ID="hlUsername" runat="server" Text='<%#Eval("trTwitterUser.Username")%>' /> <%--Buttons follow/stop following--%> <asp:Button ID="btnFollow" runat="server" Text="<%$ Resources:Localization, Follow %>" ToolTip="<%$ Resources:Localization, Follow %>" CommandName="Follow" /> <asp:Button ID="btnStopFollowing" runat="server" Text="<%$ Resources:Localization, StopFollowing %>" ToolTip="<%$ Resources:Localization, StopFollowing %>" CommandName="StopFollowing" /> <br /> <%--Text message--%> <%#Eval("Text")%> <br /> <%--Rank and plus/minus buttons--%> <asp:Label ID="lblRank" runat="server" Text='<%#Eval("Rank")%>' /> <asp:Button ID="btnPlus" runat="server" Text="+" CommandName="PlusVote" /> <asp:Button ID="btnMinus" runat="server" Text="-" CommandName="MinusVote" /> <br /> <%--TweetRank--%> <asp:Label ID="lblTweetRank" runat="server" Text='<%#Eval("TweetRank")%>' /> <br /> <%--Klout icon and KloutScore--%> <asp:Image ID="imgKlout" imageUrl="~/Resources/Images/KloutScore.png" runat="server" /> <%#Eval("trTwitterUser.KloutScore")%> <br /> <%--Date--%> <%#Eval("Date")%> </ItemTemplate> <EmptyDataTemplate> <asp:Label ID="lblNoTweets" runat="server" Text="<%$ Resources:Localization, NoTweetsFound %>" /> </EmptyDataTemplate></telerik:RadListView>I databind the list in page_load;
rlvTweets.DataSource = _db.trTweets.Where(tw => tw.Date > dt).OrderByDescending(t => t.Date);rlvTweets.DataBind();Everything works fine on the first page, the itemcommand fires, tweet is set properly... However if I use the pager the ItemCommand doesn't even fire.
protected void rlvTweets_ItemCommand(object sender, RadListViewCommandEventArgs e){ RadListViewDataItem item = (RadListViewDataItem)e.ListViewItem; trTweet tweet = (trTweet)item.DataItem;
if (e.CommandName == "PlusVote")
{
....
}}The second solution is with using the needdatasource:
ListIs the same except for needdatasource event, itemcommand is the same, the itemcommand fires everywhere now except that the item.DataItem is always null...
I removed the databinding from the page load and added it to the needdata source. I feel like I have to call the list's DataBind function somewhere, but I don't know here...
this is what i do in needdatasource:
protected void rlvTweets_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e) { DateTime dt = DateTime.Now.AddDays(-30); rlvTweets.DataSource = _db.trTweets.Where(tw => tw.Date > dt).OrderByDescending(t => t.Date); }Thanks for you help!
Sincerely, Jure