.net 2.0 FormView questions

Discussion in 'ASP .Net Datagrid Control' started by Jeronimo Bertran, Oct 20, 2005.

  1. Hello,

    I have a couple of questions about the FormView control.

    How can I access the controls I add to the ItemTemplate from the code
    behind file? For example, I added a button named Button1 to the
    ItemTemplate and I want to modify it from the codebehind.

    Can I set the pager to appear on top of the FormView just like it is done
    in the DetailsView?

    If the number of fields on my record is too large, is there a way to
    separate the fields into multiple pages in a FormView? I was thinking of
    creating a single ItemTemplate with panels that contain the controls and
    add buttons to hide and show panels within the ItemTemplate. I would need
    to do the same for the Insert and Edit templates.

    Thanks

    Jeronimo
     
    Jeronimo Bertran, Oct 20, 2005
    #1
    1. Advertising

  2. Hi Jeronimo,

    Welcome to ASPNET newsgroup.
    As for the formview questions you mentioned, here are some of my
    understanding and suggestion:

    1.For controls declared in Itemtemplate, we can access them through
    FormView.Row.FindControl(controlID)

    as long as the FormView is currently in normal readonly mode.

    2.For pager, we can set it to display at top of the FormView through the
    pagerSetting template like

    .................
    <PagerSettings Position="Top" />
    </asp:FormView>

    3. For paging for fields, i'm afraid currently it's not availabe in the
    formview since the buildin paging is records based. If you find that the
    fields count are too large, you can manually define some panel or <span> in
    the ItemTemplate and use some clientscript to let the user show or hide
    them.

    Hope helps. Thanks,


    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | Subject: .net 2.0 FormView questions
    | From: Jeronimo Bertran <>
    | Organization: Your Company
    | Message-ID: <Xns96F4DDCA784DDpublicjbbertrancom@207.46.248.16>
    | User-Agent: Xnews/??.01.30
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Date: Wed, 19 Oct 2005 21:48:09 -0700
    | NNTP-Posting-Host: c-069-063-192-218.sd2.redwire.net 69.63.192.218
    | Lines: 1
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5827
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    | Hello,
    |
    | I have a couple of questions about the FormView control.
    |
    | How can I access the controls I add to the ItemTemplate from the code
    | behind file? For example, I added a button named Button1 to the
    | ItemTemplate and I want to modify it from the codebehind.
    |
    | Can I set the pager to appear on top of the FormView just like it is done
    | in the DetailsView?
    |
    | If the number of fields on my record is too large, is there a way to
    | separate the fields into multiple pages in a FormView? I was thinking of
    | creating a single ItemTemplate with panels that contain the controls and
    | add buttons to hide and show panels within the ItemTemplate. I would
    need
    | to do the same for the Insert and Edit templates.
    |
    | Thanks
    |
    | Jeronimo
    |
    |
     
    Steven Cheng[MSFT], Oct 20, 2005
    #2
    1. Advertising

  3. Thanks Steven,

    Your were very helpful... so regarding my first question, no control
    variables are created on c# for controls I add to the template the same way
    variables are created for controls that are added to the page?


    (Steven Cheng[MSFT]) wrote in
    news:pAo#:

    > Hi Jeronimo,
    >
    > Welcome to ASPNET newsgroup.
    > As for the formview questions you mentioned, here are some of my
    > understanding and suggestion:
    >
    > 1.For controls declared in Itemtemplate, we can access them through
    > FormView.Row.FindControl(controlID)
    >
    > as long as the FormView is currently in normal readonly mode.
    >
    > 2.For pager, we can set it to display at top of the FormView through
    > the pagerSetting template like
    >
    > ................
    > <PagerSettings Position="Top" />
    > </asp:FormView>
    >
    > 3. For paging for fields, i'm afraid currently it's not availabe in
    > the formview since the buildin paging is records based. If you find
    > that the fields count are too large, you can manually define some
    > panel or <span> in the ItemTemplate and use some clientscript to let
    > the user show or hide them.
    >
    > Hope helps. Thanks,
    >
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >


    >
    >
     
    Jeronimo Bertran, Oct 20, 2005
    #3
  4. Steven,

    A couple of questions regarding hiding some controls based on the
    page....

    I basically added an html button to the headertemplate of the FormView:

    <HeaderTemplate>
    <input id="Button1" type="button" value="button"
    onclick="javascript:ShowHide()" />
    </HeaderTemplate>

    I then grouped a couple of the controls in the ItemTemplate inside a
    DIV:


    <div id="Div1">
    Field1:<asp:Label ID="Field1Label" runat="server" Text='<%# Bind
    ("Field1") %>'></asp:Label><br />
    Field2:<asp:Label ID="Field2Label" runat="server" Text='<%# Eval
    ("Field2") %>'></asp:Label><br />
    </div>
    <div id="Div2">
    Field3:<asp:Label ID="Field3Label" runat="server" Text='<%# Bind
    ("Field3") %>'></asp:Label><br />
    Field4:<asp:Label ID="Field4Label" runat="server" Text='<%# Eval
    ("Field4") %>'></asp:Label><br />
    </div>


    I then added the code to simply hide the div in order to see the
    results:

    function ShowHide()
    {
    var o = document.getElementById('Div1');
    if (o)
    {
    if (o.style.visibility == 'hidden')
    {
    o.style.visibility='visible';
    document.getElementById('Div2').style.visibility='hidden';
    }
    else
    {
    o.style.visibility='hidden';
    document.getElementById('Div2').style.visibility='visible';
    }
    }

    }

    This does hide the content inside DIV1 when I press the button and shows
    the contents of DIV2, but the space taken by each DIV remains blank
    after hiding and therefore it is like having an empty page before we get
    to the controls on the second DIV.

    I tried using an asp:panel instead of the div.... but I am unable to
    access the panel from my script.... I basically change the DIV1 tag to
    the following:

    <asp:panel ID="Div1" runat="server">

    but now getElementByID('Div1') return null.

    THanks again,

    Jeronimo
     
    Jeronimo Bertran, Oct 20, 2005
    #4
  5. Hi Jeronimo,

    Thanks for your response.

    For your question in the first response
    ===========
    so regarding my first question, no control
    variables are created on c# for controls I add to the template the same way
    variables are created for controls that are added to the page?
    ===================

    Yes, for sub controls nested in other container controls on the page, there
    won't have direct control property in page class to access them. Only top
    level controls has such member properties in page.

    As for the showhide function, you can use the following code instead of
    your original one:

    =================================
    function showhidetwo()
    {
    var div = document.getElementById("divTwo");
    if(div.style.display != "none")
    {
    div.style.display = "none";
    }else
    {
    div.style.display = "inline";
    }
    }
    ============================

    the style.display can help hidden the html element and won't occupy the
    space as well.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | Subject: RE: .net 2.0 FormView questions
    | From: Jeronimo Bertran <>
    | References: <Xns96F4DDCA784DDpublicjbbertrancom@207.46.248.16>
    <PAo#>
    | Organization: Your Company
    | Message-ID: <Xns96F5A10B4DFDCpublicjbbertrancom@207.46.248.16>
    | User-Agent: Xnews/??.01.30
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Date: Thu, 20 Oct 2005 15:49:50 -0700
    | NNTP-Posting-Host: c-069-063-192-218.sd2.redwire.net 69.63.192.218
    | Lines: 1
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5840
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    | Steven,
    |
    | A couple of questions regarding hiding some controls based on the
    | page....
    |
    | I basically added an html button to the headertemplate of the FormView:
    |
    | <HeaderTemplate>
    | <input id="Button1" type="button" value="button"
    | onclick="javascript:ShowHide()" />
    | </HeaderTemplate>
    |
    | I then grouped a couple of the controls in the ItemTemplate inside a
    | DIV:
    |
    |
    | <div id="Div1">
    | Field1:<asp:Label ID="Field1Label" runat="server" Text='<%# Bind
    | ("Field1") %>'></asp:Label><br />
    | Field2:<asp:Label ID="Field2Label" runat="server" Text='<%# Eval
    | ("Field2") %>'></asp:Label><br />
    | </div>
    | <div id="Div2">
    | Field3:<asp:Label ID="Field3Label" runat="server" Text='<%# Bind
    | ("Field3") %>'></asp:Label><br />
    | Field4:<asp:Label ID="Field4Label" runat="server" Text='<%# Eval
    | ("Field4") %>'></asp:Label><br />
    | </div>
    |
    |
    | I then added the code to simply hide the div in order to see the
    | results:
    |
    | function ShowHide()
    | {
    | var o = document.getElementById('Div1');
    | if (o)
    | {
    | if (o.style.visibility == 'hidden')
    | {
    | o.style.visibility='visible';
    | document.getElementById('Div2').style.visibility='hidden';
    | }
    | else
    | {
    | o.style.visibility='hidden';
    | document.getElementById('Div2').style.visibility='visible';
    | }
    | }
    |
    | }
    |
    | This does hide the content inside DIV1 when I press the button and shows
    | the contents of DIV2, but the space taken by each DIV remains blank
    | after hiding and therefore it is like having an empty page before we get
    | to the controls on the second DIV.
    |
    | I tried using an asp:panel instead of the div.... but I am unable to
    | access the panel from my script.... I basically change the DIV1 tag to
    | the following:
    |
    | <asp:panel ID="Div1" runat="server">
    |
    | but now getElementByID('Div1') return null.
    |
    | THanks again,
    |
    | Jeronimo
    |
    |
    |
    |
    |
    |
     
    Steven Cheng[MSFT], Oct 21, 2005
    #5
  6. Thanks Steven... worked great.

    Jeronimo
     
    Jeronimo Bertran, Oct 25, 2005
    #6
  7. You're welcome Jeronimo,

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | Subject: RE: .net 2.0 FormView questions
    | From: Jeronimo Bertran <>
    | References: <Xns96F4DDCA784DDpublicjbbertrancom@207.46.248.16>
    <PAo#>
    <Xns96F5A10B4DFDCpublicjbbertrancom@207.46.248.16>
    <>
    | Organization: Your Company
    | Message-ID: <Xns96F9C84C3CCE8publicjbbertrancom@207.46.248.16>
    | User-Agent: Xnews/??.01.30
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | Date: Mon, 24 Oct 2005 19:41:19 -0700
    | NNTP-Posting-Host: c-069-063-192-218.sd2.redwire.net 69.63.192.218
    | Lines: 1
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5855
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    | Thanks Steven... worked great.
    |
    | Jeronimo
    |
     
    Steven Cheng[MSFT], Oct 25, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelly

    DataSource and FormView questions

    Kelly, Aug 8, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,823
    Kelly
    Aug 9, 2006
  2. Q. John Chen

    FormView Questions

    Q. John Chen, Nov 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    313
    Q. John Chen
    Nov 9, 2006
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    545
    Chris
    May 19, 2007
  4. dan
    Replies:
    2
    Views:
    1,081
  5. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    656
    David Thielen
    Jun 16, 2006
Loading...

Share This Page