Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

ListView control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Gaze - 12 Apr 2008 08:24 GMT
I have created a ListView control and have bound this to a datasource.
Within the ItemTemplate of the ListView I have added another ListViewControl
which is databound in the code behind. The idea is that when clicking on the
"Show details" button the ListView for the appropriate row binds in the
codebehind and displays the detail data for the selected row. I did
something similar with a gridview control previously, but want to be able to
fully control the HTML produced now so don't want to go down that route.

The problem I am having is that the master ListView renders with the correct
data, but the embedded details ListView does not display at all. If I pull
the details ListView out of the master ListView and create seperately it
does render correctly. Is the problem being caused because the master
ListView is rendering before the details ListView is generated? Any help
appreciated.

Regards

Brian

Here's the code......

I'm trying to bind the details ListView in  the SelectedIndexChanged event
of the master ListView, with something like this in the codebehind:

 ListView tmp = new ListView();
 tmp = (ListView)this.ListView1.Items[rowcount].FindControl("lvDetails");
 tmp.DataSourceID = "ods1";
 tmp.DataBind();

The declarative code is...

 <ItemTemplate>
           <tr>
               <td>
                    <asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Select"
                       Text="Show details"
OnClick="LinkButton1_Click"></asp:LinkButton>
                   <asp:LinkButton ID="LinkButton2" runat="server"
CausesValidation="False" CommandName="Cancel"
                       Text="Hide details"></asp:LinkButton>
                   <asp:Label ID="Label10" runat="server" Text='<%#
Eval("[Field1]") + "kmh" %>'></asp:Label>
               </td>
               <td>
                   <asp:Label ID="Label9" runat="server" Text='<%#
Eval("Field2")  + "mB"%>'></asp:Label>
               </td>
             </tr>
             <tr>
                 <td colspan="2">
                     <asp:ListView ID="lvDetails" runat="server"
EnableViewState="false">
                         <LayoutTemplate>
                             <ul>
                                 <asp:PlaceHolder ID="itemPlaceholder"
runat="server"></asp:PlaceHolder>
                              </ul>
                          </LayoutTemplate>
                          <ItemTemplate>
                               <li>
                                   <%# Eval("[Wind speed]")%>
                                   <%# Eval("[Temperature]")%>
                                 </li>
                           </ItemTemplate>
                           </asp:ListView>
                       </td>

             </tr>
 </ItemTemplate>
Eliyahu Goldin - 13 Apr 2008 10:58 GMT
The line
ListView tmp = new ListView();
is not needed. You are creating an instance of ListView and the next line is
going to override the reference to this instance with the one already
defined in the template. But that is not the reason for your problem.

In declarative databinding you need to run Select on the datasource to get
the data programmatically. Without this, tmp.Databind() won't help since it
will bind to an empty datasource. Replace
tmp.DataBind();
with
ods1.Select()
and see if it works.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

>I have created a ListView control and have bound this to a datasource.
>Within the ItemTemplate of the ListView I have added another
[quoted text clipped - 67 lines]
>              </tr>
>  </ItemTemplate>
Brian Gaze - 13 Apr 2008 22:20 GMT
Thanks - that resolves the problem I was having with sub ListView not
rendering, but introduces another issue. A sub ListView (with the same data
in each case)  is rendered for each item returned in the master ListView.
What I'm trying to do is only render a sub ListView for the item currently
selected in the master ListView.

Any ideas?

Brian

> The line
> ListView tmp = new ListView();
[quoted text clipped - 81 lines]
>>              </tr>
>>  </ItemTemplate>
Eliyahu Goldin - 14 Apr 2008 09:33 GMT
Why is it rendered for each item? Don't you handle the SelectedIndexChanged
event? In any case, since you are already in code-behind, you can code any
logic as when to populate the sub listview.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Thanks - that resolves the problem I was having with sub ListView not
> rendering, but introduces another issue. A sub ListView (with the same
[quoted text clipped - 93 lines]
>>>              </tr>
>>>  </ItemTemplate>
Brian Gaze - 28 Apr 2008 08:15 GMT
Thanks. The easiest solution for me was to add the sub ListView
declaratively in the SelectedItemtemplate.

Brian

> Why is it rendered for each item? Don't you handle the
> SelectedIndexChanged event? In any case, since you are already in
[quoted text clipped - 98 lines]
>>>>              </tr>
>>>>  </ItemTemplate>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.