473,221 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

ListView control

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>
Jun 27 '08 #1
4 4448
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.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
>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>

Jun 27 '08 #2
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
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eB**************@TK2MSFTNGP04.phx.gbl...
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.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
>>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>


Jun 27 '08 #3
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
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
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eB**************@TK2MSFTNGP04.phx.gbl...
>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.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
>>>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>



Jun 27 '08 #4
Thanks. The easiest solution for me was to add the sub ListView
declaratively in the SelectedItemtemplate.

Brian

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uI**************@TK2MSFTNGP04.phx.gbl...
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.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:OU**************@TK2MSFTNGP03.phx.gbl...
>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
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eB**************@TK2MSFTNGP04.phx.gbl...
>>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.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Brian Gaze" <br********@removetheweatheroutlook.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
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>



Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pointBoarder | last post by:
I'm following the article from http://support.microsoft.com/default.aspx?scid=kb;en-us;155178 The above article explains how to fill a listview. For some reason I keep recieving "User-defined...
1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
1
by: Riccardo Giomi | last post by:
Hi I would to display a Cursors.WaitCursor on a ListView control, so I tried listView.Cursor = Cursors.WaitCursor but it doesn't work at all, I see always the default cursor. The same thing...
0
by: willow1480 | last post by:
I am developing a small little Service Control Application. I am using a listview control with checkboxes and getting the list of services I want to control from a text file. When you check a...
4
by: Ira Siyal | last post by:
Hi I had a project in VB6 which I upgraded to VB.NET recently. In the app, I am facing some issue with listview control. In the earlier app, I have set the Icons in listview through an...
12
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView...
6
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is...
2
by: =?Utf-8?B?SXJmYW4=?= | last post by:
Hello, It may be a repeated question but I don't find the solution to the situation that I encounter in it. My application is monitoring another application that is built in VB6. The...
1
by: FireFlux | last post by:
Inherit the Listview Control with Visual Basic ? I have decided do inherit the Listview control some days ago to change some painting things to make the .net Listview look like the explorer's...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.