ListView control

ListView control

am 12.04.2008 09:24:50 von Brian Gaze

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("lvDeta ils");
tmp.DataSourceID = "ods1";
tmp.DataBind();


The declarative code is...




CausesValidation="False" CommandName="Select"
Text="Show details"
OnClick="LinkButton1_Click">

CausesValidation="False" CommandName="Cancel"
Text="Hide details">









EnableViewState="false">





  • <%# Eval("[Wind speed]")%>
    <%# Eval("[Temperature]")%>






  • Re: ListView control

    am 13.04.2008 11:58:54 von Eliyahu Goldin

    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" wrote in message
    news:uVsyA6GnIHA.4536@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("lvDeta ils");
    > tmp.DataSourceID = "ods1";
    > tmp.DataBind();
    >
    >
    > The declarative code is...
    >
    >
    >
    >
    > > CausesValidation="False" CommandName="Select"
    > Text="Show details"
    > OnClick="LinkButton1_Click">

    > > CausesValidation="False" CommandName="Cancel"
    > Text="Hide details">

    >
    >
    >
    >
    >
    >
    >
    >
    > > EnableViewState="false">
    >
    >


    >
    >
    >

  • > <%# Eval("[Wind speed]")%>
    > <%# Eval("[Temperature]")%>
    >

  • >

    >
    >
    >
    >
    >
    >

    Re: ListView control

    am 13.04.2008 23:20:31 von Brian Gaze

    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" wrote in
    message news:eBv8m0UnIHA.1184@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" wrote in message
    > news:uVsyA6GnIHA.4536@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("lvDeta ils");
    >> tmp.DataSourceID = "ods1";
    >> tmp.DataBind();
    >>
    >>
    >> The declarative code is...
    >>
    >>
    >>
    >>
    >> >> CausesValidation="False" CommandName="Select"
    >> Text="Show details"
    >> OnClick="LinkButton1_Click">

    >> >> CausesValidation="False" CommandName="Cancel"
    >> Text="Hide details">

    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> >> EnableViewState="false">
    >>
    >>


    >>
    >>
    >>

  • >> <%# Eval("[Wind speed]")%>
    >> <%# Eval("[Temperature]")%>
    >>

  • >>

    >>
    >>
    >>
    >>
    >>
    >>
    >
    >

    Re: ListView control

    am 14.04.2008 10:33:10 von Eliyahu Goldin

    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" wrote in message
    news:OUv1qxanIHA.1204@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" wrote in
    > message news:eBv8m0UnIHA.1184@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" wrote in message
    >> news:uVsyA6GnIHA.4536@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("lvDeta ils");
    >>> tmp.DataSourceID = "ods1";
    >>> tmp.DataBind();
    >>>
    >>>
    >>> The declarative code is...
    >>>
    >>>
    >>>
    >>>
    >>> >>> CausesValidation="False" CommandName="Select"
    >>> Text="Show details"
    >>> OnClick="LinkButton1_Click">

    >>> >>> CausesValidation="False" CommandName="Cancel"
    >>> Text="Hide details">

    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> >>> EnableViewState="false">
    >>>
    >>>


    >>>
    >>>
    >>>

  • >>> <%# Eval("[Wind speed]")%>
    >>> <%# Eval("[Temperature]")%>
    >>>

  • >>>

    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>
    >>
    >
    >