TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mike
NA
3
4.6k
Listview/Datapager inside AJAX Accordion with custom data source
Jun 3 2011 4:03 PM
Disclaimer: 1st post - so I'm a newb....please point me to correct forum if this is not the appropriate one for this issue.
I have an ajax accordion that contains a listview in each pane. The listview's layouttemplate contains a datapager. I'm querying data contained in a SQL database in the codebehind. The number of accordion panes is determined by a field called "category" and under each pane is a listview containing the title and a pic of the software associated with that category. So I am binding the accordion then binding the listviews essentially. When I expand one of the panes and attempt to page through the listview (i.e. click on the "2" or "3") there are two primary issues. #1 - I have to click the the page buttons (i.e. the number 2 or 3) twice to get the listview to do anything and #2 - the same data is listed no matter what page it think's I'm on. So for example, on page 1 the listview displays the software "Acrobat", "Illustrator", "Photoshop" - when I click on page 2 (twice) I still see "Acrobat", "Illustrator", "Photoshop" when I should see "InDesign, "Dreamweaver", and "Flexbuilder". It appears to be posting back each time I click the buttons in the datapager but I still see this same behavior.
Here's my markup:
<asp:Accordion ID="Accordion1" runat="server"
ContentCssClass="accordionContent" CssClass="accordion"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" SuppressHeaderPostbacks="true" Width="100%" RequireOpenedPane="true">
<HeaderTemplate>
<asp:Label ID="lblHeaderCategory" runat="server" Text='<%# Eval("category") %>'></asp:Label>
</HeaderTemplate>
<ContentTemplate>
<asp:HiddenField runat="server" id="hf1" value='<%# Eval("category") %>'></asp:HiddenField>
<asp:ListView ID="lvFilterSW" runat="server" GroupItemCount="5" Visible="True"
OnPagePropertiesChanging="lvFilterSW_PagePropertiesChanging" OnPagePropertiesChanged="lvFilterSW_PagePropertiesChanged">
<LayoutTemplate>
<table ID="tblItems" runat="server" cellpadding="3" style="border-bottom-style: ridge">
<tr ID="groupPlaceholder" runat="server"></tr>
</table>
<asp:DataPager ID="dplvFilterSW" runat="server" PageSize="15" PagedControlID="lvFilterSW" OnPreRender="dplvFilterSW_PreRender">
<Fields>
<asp:NumericPagerField NextPageText="-->" PreviousPageText="<--"/>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<GroupTemplate>
<tr ID="ProductRow" runat="server" style="height:100px">
<td ID="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td1" runat="server" align="center" style="width:80px" valign="top">
<asp:HyperLink ID="ProductPicLink" runat="server" NavigateUrl='<%# "~/product.aspx?title=" & Eval("title") %>'>
<img src='<%# "images/" + Eval("ProductPic") %>' border="0" height="70" width="70" />
</asp:HyperLink>
<br />
<asp:HyperLink ID="ProductLink" runat="server" NavigateUrl='<%# "~/product.aspx?title=" & Eval("title") %>'
Text='<% #Eval("title") %>'></asp:HyperLink>
</td>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:Accordion>
Here is my code behind (what's relevant to this question):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim sParameter As String = "PointlessForThisQuestion" 'Used for building custom SQL statements in other parts of the code
BindAccordion(sParameter)
End If
End Sub
Private Sub BindAccordion(ByVal sParameter As String)
Dim connStringProduct As String = ConfigurationManager.ConnectionStrings("SoftwareTestConnectionString2").ConnectionString
Dim sql As String = "SELECT DISTINCT category FROM ApprovedSoftware WHERE Availability='Global'"
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, connStringProduct)
Dim dt As New DataTable
da.Fill(dt)
Accordion1.DataSource = dt.DefaultView
Accordion1.DataBind()
Accordion1.RequireOpenedPane = False
Accordion1.SelectedIndex = -1
End Sub
Private Sub Accordion1_ItemDataBound(ByVal sender As Object, ByVal e As AjaxControlToolkit.AccordionItemEventArgs) Handles Accordion1.ItemDataBound
If e.ItemType = AccordionItemType.Content Then
Dim listview1 As ListView = e.AccordionItem.FindControl("lvFilterSW")
Dim hidField As HiddenField = e.AccordionItem.FindControl("hf1")
BindGrid(listview1, hidField.Value, "")
End If
End Sub
Private Sub BindGrid(ByVal lvMain As ListView, ByVal category As String, ByVal sql As String)
Dim connStringProduct As String = ConfigurationManager.ConnectionStrings("SoftwareTestConnectionString2").ConnectionString
Dim sql As String = "SELECT DISTINCT title, productPic FROM ApprovedSoftware WHERE category='" & category & _
"' AND Availability='Global'"
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, connStringProduct)
da.SelectCommand.Parameters.Add("@title", SqlDbType.VarChar, 20).Value = Title
Dim dt As New DataTable
da.Fill(dt)
lvMain.DataSource = dt
lvMain.DataBind()
End Sub
Protected Sub lvFilterSW_PagePropertiesChanging(ByVal sender As Object, ByVal e As PagePropertiesChangingEventArgs)
Dim dp As New DataPager
Dim lv As New ListView
Dim hf As HiddenField
Dim sql As String = ""
'lv = Me.Accordion1.FindControl("lvFilterSW")
lv = CType(Me.Accordion1.FindControl("lvFilterSW"), ListView)
'dp = lv.FindControl("dplvFilterSW")
dp = CType(lv.FindControl("dplvFilterSW"), DataPager)
hf = Me.Accordion1.FindControl("hf1")
dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
BindGrid(lv, hf.Value, sql)
End Sub
Protected Sub dplvFilterSW_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Dim dp As New DataPager
Dim lv As New ListView
Dim hf As HiddenField
Dim sql As String = ""
'lv = Me.Accordion1.FindControl("lvFilterSW")
lv = CType(Me.Accordion1.FindControl("lvFilterSW"), ListView)
'dp = lv.FindControl("dplvFilterSW")
dp = CType(lv.FindControl("dplvFilterSW"), DataPager)
hf = Me.Accordion1.FindControl("hf1")
BindGrid(lv, hf.Value, sql)
End Sub
I know the code is repetive but for now I'm trying to just get this working then I will clean up the code. I've tried changing the datasource from a dataTable to a DataSet but still get the same results.
Let me know if any other info is needed, be glad to pass along.
Thanks in advance.
Reply
Answers (
1
)
Whats better Dynamic cotrol or Gridview
Invalid column name ''.