473,839 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SelectedIndexCh anged event
of the master ListView, with something like this in the codebehind:

ListView tmp = new ListView();
tmp = (ListView)this. ListView1.Items[rowcount].FindControl("l vDetails");
tmp.DataSourceI D = "ods1";
tmp.DataBind();
The declarative code is...

<ItemTemplate >
<tr>
<td>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="False" CommandName="Se lect"
Text="Show details"
OnClick="LinkBu tton1_Click"></asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 " runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
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:PlaceHolde r ID="itemPlaceho lder"
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 4525
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 programmaticall y. 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********@rem ovetheweatherou tlook.comwrote in message
news:uV******** ******@TK2MSFTN GP06.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
ListViewContro l 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 SelectedIndexCh anged event
of the master ListView, with something like this in the codebehind:

ListView tmp = new ListView();
tmp = (ListView)this. ListView1.Items[rowcount].FindControl("l vDetails");
tmp.DataSourceI D = "ods1";
tmp.DataBind();
The declarative code is...

<ItemTemplate >
<tr>
<td>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="False" CommandName="Se lect"
Text="Show details"
OnClick="LinkBu tton1_Click"></asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 " runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
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:PlaceHolde r ID="itemPlaceho lder"
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.orgwro te in
message news:eB******** ******@TK2MSFTN GP04.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 programmaticall y. 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********@rem ovetheweatherou tlook.comwrote in message
news:uV******** ******@TK2MSFTN GP06.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
ListViewContr ol 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 SelectedIndexCh anged
event of the master ListView, with something like this in the codebehind:

ListView tmp = new ListView();
tmp = (ListView)this. ListView1.Items[rowcount].FindControl("l vDetails");
tmp.DataSourceI D = "ods1";
tmp.DataBind();
The declarative code is...

<ItemTemplate >
<tr>
<td>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidati on="False" CommandName="Se lect"
Text="Show details"
OnClick="LinkB utton1_Click"></asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 " runat="server"
CausesValidati on="False" CommandName="Ca ncel"
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"
EnableViewStat e="false">
<LayoutTemplate >
<ul>
<asp:PlaceHolde r ID="itemPlaceho lder"
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 SelectedIndexCh anged
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********@rem ovetheweatherou tlook.comwrote in message
news:OU******** ******@TK2MSFTN GP03.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.orgwro te in
message news:eB******** ******@TK2MSFTN GP04.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 programmaticall y. 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********@rem ovetheweatherou tlook.comwrote in message
news:uV******* *******@TK2MSFT NGP06.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
ListViewCont rol which is databound in the code behind. The idea is that
when clicking on the "Show details" button the ListView for the
appropriat e 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 SelectedIndexCh anged
event of the master ListView, with something like this in the
codebehind:

ListView tmp = new ListView();
tmp =
(ListView)thi s.ListView1.Ite ms[rowcount].FindControl("l vDetails");
tmp.DataSourceI D = "ods1";
tmp.DataBind();
The declarative code is...

<ItemTemplate >
<tr>
<td>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidat ion="False" CommandName="Se lect"
Text="Show details"
OnClick="Link Button1_Click"> </asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 " runat="server"
CausesValidat ion="False" CommandName="Ca ncel"
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"
EnableViewSta te="false">
<LayoutTemplate >
<ul>
<asp:PlaceHolde r ID="itemPlaceho lder"
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 SelectedItemtem plate.

Brian

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:uI******** ******@TK2MSFTN GP04.phx.gbl...
Why is it rendered for each item? Don't you handle the
SelectedIndexCh anged 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********@rem ovetheweatherou tlook.comwrote in message
news:OU******** ******@TK2MSFTN GP03.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.orgwro te in
message news:eB******** ******@TK2MSFTN GP04.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 programmaticall y. 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********@rem ovetheweatherou tlook.comwrote in message
news:uV****** ********@TK2MSF TNGP06.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
ListViewCon trol which is databound in the code behind. The idea is that
when clicking on the "Show details" button the ListView for the
appropria te row binds in the codebehind and displays the detail data for
the selected row. I did something similar with a gridview control
previousl y, 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 SelectedIndexCh anged
event of the master ListView, with something like this in the
codebehind :

ListView tmp = new ListView();
tmp =
(ListView)th is.ListView1.It ems[rowcount].FindControl("l vDetails");
tmp.DataSourceI D = "ods1";
tmp.DataBind();
The declarative code is...

<ItemTemplate >
<tr>
<td>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValida tion="False" CommandName="Se lect"
Text="Show details"
OnClick="Lin kButton1_Click" ></asp:LinkButton>
<asp:LinkButt on ID="LinkButton2 " runat="server"
CausesValida tion="False" CommandName="Ca ncel"
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"
EnableViewSt ate="false">
<LayoutTemplate >
<ul>
<asp:PlaceHolde r ID="itemPlaceho lder"
runat="serve r"></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
5788
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 type not defined" on line Dim NewLine As ListItem there is a note in the article that says:
1
5976
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. I would like to assign each control to a listview object, however I get a type mismatch. Further investigation reveals that the type of the control is "Custom Control" and not a listview. I would like to be able to work with real control object's...
1
2545
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 happens if I set the WaitCursor in the properties window. The strange thing is that with other controls, like buttons or the treeview, it does work. The only control for which I can't change the cursor is the ListView: it does not work even if I set...
0
2355
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 checkbox, it should either stop the service or start the service depending on each respective service's status. I want the listView to update the status for each service as they are checked. instead all I can seem to do is clear the listView and I...
4
2241
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 imagelist. but i notice that while i execute the project in .net, the step that sets the icon prop. throws an exception.
12
3144
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 control in code and add it to the form, it works. Why don't the items show up in the ListView that I added at desgn time. ' Create three items and three sets of subitems for each item. Dim item1 As New ListViewItem("item1", 0) ' Place a check...
6
5045
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 this possible? I intend on replacing an ActiveX grid with a listview control from a VB6 application that I've upgraded to VB .NET. The existing functionlality uses the mouseover event of the grid to display specific information within...
2
5068
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 application monitors all the textboxes and other input & display controls on that application. The data from the textboxes and listboxes are retrived fine. But, when it comes to Listview there I got memory exception. I know that I need to do the in memory...
1
1948
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 Listview. I am very new on doing those things like painting and also have not much practise with inheriting , so I got some problems while I tried to change the Control to that Listview I like. Here are my Questions : - Can I run a method if...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7828
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3134
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.