.net 2.0 FormView questions

J

Jeronimo Bertran

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
 
S

Steven Cheng[MSFT]

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 <[email protected]>
| Organization: Your Company
| Message-ID: <[email protected]>
| 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
|
|
 
J

Jeronimo Bertran

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?


(e-mail address removed) (Steven Cheng[MSFT]) wrote in
 
J

Jeronimo Bertran

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
 
S

Steven Cheng[MSFT]

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 <[email protected]>
| References: <[email protected]>
<PAo#[email protected]>
| Organization: Your Company
| Message-ID: <[email protected]>
| 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
|
|
|
|
|
|
 
S

Steven Cheng[MSFT]

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 <[email protected]>
| References: <[email protected]>
<PAo#[email protected]>
<[email protected]>
<[email protected]>
| Organization: Your Company
| Message-ID: <[email protected]>
| 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
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FormView 0
FormView 3
No fields in FormView 1
FormView insert with UpdatePanel 0
FormView and Master Page 0
FormView Buttons 1
FormView and Master Page 0
FormView Buttons 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top