Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

formview control question

19 views
Skip to first unread message

TdarTdar

unread,
Oct 6, 2005, 12:34:01 AM10/6/05
to
I have a form view control linked to a sql database
with the database fields of:

lenght
weidth
height
oversize

I would like to access the lenght after user types in values to
run some math to determine what oversize shoud be and enter
that in automatically before the fromview insert is clicked

However since i am new to working with these controls not sure what
to do.

In the past it would be like:

oversize.text = lenght.text + width.text

so in recap:

formview control linked to database

fields:
lenght: 21 < - user types in
width: 11 < - user types in
oversize: 32 <- computer does math and enters

THEN user submits the form view to enter data into database.


Steven Cheng[MSFT]

unread,
Oct 6, 2005, 5:09:30 AM10/6/05
to
Hi Tdar ,

Thanks for your posting.
regarding on this issue, I've also noticed your another thread in the

Subject: RE: asp.net 2.0 beta2 and formview
Newsgroups: microsoft.public.dotnet.framework.aspnet

I've posted my response there. As mentioned in that message, when we define
some inner controls in the
formview's template, we can access them through the

FormView.Row.FindControl( controlID)

controlID is the ID of the control you defined in the formView's certain
template. Also, we can only retrieve control instance in a certain template
when the template is in active. In other word, in normal mode, we can
access controls in ItemTemplate through
FormView.Row.FindControl( controlID)

and only in Edit mode can we access controls in Edit template.

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security


--------------------
| Thread-Topic: formview control question
| thread-index: AcXKLyzepemS1lAGQN6bchXeDwgm3A==
| X-WBNR-Posting-Host: 65.35.95.11
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <Td...@noemail.nospam>
| Subject: formview control question
| Date: Wed, 5 Oct 2005 21:34:01 -0700
| Lines: 33
| Message-ID: <320E0B58-3629-44D7...@microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:11186
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

TdarTdar

unread,
Oct 6, 2005, 11:03:06 AM10/6/05
to
So what are you saying here that I would use something like
Girth = FormView1.Row.FindControl("LEGNTHTEXTBOX") +
FormView1.Row.FindControl("WIDTHTEXTBOX")

but how do i get the .text value of what the user entered in
and i was using that FormView1_PageIndexChanging to triger the
procedure and had default value of 0.

I guess i am tring do something that is not possiable, I am VERY new
to asp.net in general I have a Goal of just using and working within your
controls to speed up development.

I have been watching the training on ASP.net 2.0 and just have not run acrosed
this i guess more advanced information.

Frankly i have not seen any training on how to modify the contants of a
form/details view in respects to say making one field a drop down select
from a data connection for a inserting or updating a data record, I still
find myself having to make a from for that granted I am sure that is jsut
drag in a field also but then having to do that it makes the use of your new
facny controls somewhat limited.
So if there is something written up or a video show on eather of these
subjects please point me in the right direction also if you could please
provide an example of what i am asking for re the lenght width it would be
helpfull i learn much faster by seeing how it is done ....

Steven Cheng[MSFT]

unread,
Oct 6, 2005, 11:23:48 PM10/6/05
to
Thanks for your response Tdar,

Here is a simple example demonstrate the things I mentioend earlier.
Suppose we have the following FormView and ItemTemplate defined:

<asp:FormView id="FormView1" ....>
........

<ItemTemplate>
CategoryID:
<asp:Label ID="CategoryIDLabel" runat="server" Text='<%#
Eval("CategoryID") %>'>
</asp:Label><br />
CategoryName:
<asp:Label ID="CategoryNameLabel" runat="server" Text='<%#
Bind("CategoryName") %>'>
</asp:Label><br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Bind("Description") %>'>
</asp:Label><br />
</ItemTemplate>

</asp:FormView>

So when we want to retrieve the binded data in the current displayed
record(in normal mode), we can use the following code to find those Label
controls' reference and access their text propety.


protected void Button1_Click(object sender, EventArgs e)
{
Label lblID = FormView1.Row.FindControl("CategoryIDLabel") as Label;
Label lblName = FormView1.Row.FindControl("CategoryNameLabel") as Label;
Label lblDesc = FormView1.Row.FindControl("DescriptionLabel") as Label;

Response.Write("<br>CategoryID: " + lblID.Text);
Response.Write("<br>CategoryName: " + lblName.Text);
Response.Write("<br>Description: " + lblDesc.Text);
}

Also, if you use TextBox instead, just change the control type to TextBox.
And as I've also mentioned, we can only access the controls which is in the
active template (ItemTemplate, EditTemplate , InsertTemplate ....).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security


--------------------
| Thread-Topic: formview control question

| thread-index: AcXKhw7stEqxcoBPTcaCiJA3aOg3Dw==
| X-WBNR-Posting-Host: 24.73.223.27
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <Td...@noemail.nospam>
| References: <320E0B58-3629-44D7...@microsoft.com>
<2xJWmWly...@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: formview control question
| Date: Thu, 6 Oct 2005 08:03:06 -0700
| Lines: 123
| Message-ID: <2342EFEC-782B-44EE...@microsoft.com>


| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250

| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:11198
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

TdarTdar

unread,
Oct 8, 2005, 10:50:01 AM10/8/05
to
This is helpfull, however,

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim output As String
Label lbldesc = FormView1.Row.FindControl("heightLabel") as string
output = lbldesc.text
MsgBox(output)
End Sub


When i use the "label" as the first word it:
Error 9 'label' is a type and cannot be used as an expression.

If i do :

Dim output As String, lblid
lblid = FormView1.Row.FindControl("lengthLabel")
output = lblid.text
MsgBox(output)

not sure what TYpe it is looking for I try string and i get value of type
'system.web.ui.control cannot be converted to string.
I tried array as thing


"Steven Cheng[MSFT]" wrote:

> Thanks for your response Tdar,
>
> Here is a simple example demonstrate the things I mentioend earlier.
> Suppose we have the following FormView and ItemTemplate defined:
>
> <asp:FormView id="FormView1" ....>

> .........

Steven Cheng[MSFT]

unread,
Oct 9, 2005, 9:26:51 PM10/9/05
to
Thanks for your followup Tdar,

From the code snippet you provided, I think the problem is caused by the
following line:

Label lbldesc = FormView1.Row.FindControl("heightLabel") as string

Label lbldesc
is the variable declaration style in C#, also there is no "as" in VB.NET.
in VB.NET, we should use

dim lbldesc as Label

lbldesc = FormView1.Row.FindControl("heightLabel")

if you feel necessary, you can also do a explicit cast like:

lbldesc = CType(Label, FormView1.Row.FindControl("heightLabel"))

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security

--------------------
| Thread-Topic: formview control question

| thread-index: AcXMF4+WJb7S9lZTSFujx5IamwNZrg==


| X-WBNR-Posting-Host: 24.73.223.27
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <Td...@noemail.nospam>
| References: <320E0B58-3629-44D7...@microsoft.com>
<2xJWmWly...@TK2MSFTNGXA01.phx.gbl>

<2342EFEC-782B-44EE...@microsoft.com>
<p#EXQ6uyF...@TK2MSFTNGXA01.phx.gbl>


| Subject: RE: formview control question

| Date: Sat, 8 Oct 2005 07:50:01 -0700
| Lines: 244
| Message-ID: <0C8C8CA2-70E2-4DC6...@microsoft.com>


| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl

microsoft.public.dotnet.framework.aspnet.webcontrols:11229
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

TdarTdar

unread,
Oct 10, 2005, 11:30:04 AM10/10/05
to
Hi thanks for bearing with me, here is what i get now :(

Dim lbldesc As Label, output As String


lbldesc = FormView1.Row.FindControl("heightLabel")

output = lbldesc.Text
MsgBox(output)
error:
Implicit conversion from 'System.Web.UI.Control' to
'System.Web.UI.WebControls.Label'.

or if i use

lbldesc = CType(Label, FormView1.Row.FindControl("heightLabel"))

error:
Array bounds cannot appear in type specifiers.
'Label' is a type and cannot be used as an expression.
Type 'FormView1.Row.FindControl' is not defined.


Thanks again for the help

David

Steven Cheng[MSFT]

unread,
Oct 10, 2005, 9:12:45 PM10/10/05
to
Hi David,

Thanks for your further response.
I'm surprised that you can not implicitly convert the Label instance
directly through object reference since it works well on myside. And for
your seconed statement, you should switch the two parameters (the first
parameter of "CType", should be the object instance, and the second should
be the Type name). Here is the code worked on my side:

Dim lbl As Label

'this is the implicit cast
'lbl = FormView1.Row.FindControl("CategoryNameLabel")

'explicit cast
lbl = CType(FormView1.Row.FindControl("CategoryNameLabel"), Label)

If Not lbl Is Nothing Then
Response.Write("<br>CategoryName: " + lbl.Text)
End If

TdarTdar

unread,
Oct 11, 2005, 12:01:04 PM10/11/05
to
What version of vs 2005 are you using I am using beta 2.. Could that be it?

TdarTdar

unread,
Oct 11, 2005, 12:29:03 PM10/11/05
to
CType(FormView1.Row.FindControl("CategoryNameLabel"), Label)

That also did the Trick, Thanks for hanging in with me...

David

TdarTdar

unread,
Oct 11, 2005, 12:40:02 PM10/11/05
to
Ugh sorry one more,
How do i fill a value back into your controls:

FormView1.Row.FindControl("CategoryNameLabel") .text = "Whatever"

that does not seem to be right, unless it is because i am in beta 2 ???

David

Steven Cheng[MSFT]

unread,
Oct 11, 2005, 9:41:30 PM10/11/05
to
Hi David,

Thanks for your further followup.
For my test, I also used a beta2 environment of the .NET 2.0/VS.NET 2005.
Anyway, I think it should be a environment specific problem since VB.NET
should by default support late binding accessing object members. Currently
you can still try using explicit casting first before access control member
like:

dim lbl as Label

lbl = CType(FormView1.Row.FindControl("CategoryNameLabel"), Label)

lbl.Text = xxxxx

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security


--------------------
| Thread-Topic: formview control question

| thread-index: AcXOgm1Zab+AnxnYT2aHY3zbeVUZTQ==


| X-WBNR-Posting-Host: 24.73.223.27
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <Td...@noemail.nospam>
| References: <320E0B58-3629-44D7...@microsoft.com>
<2xJWmWly...@TK2MSFTNGXA01.phx.gbl>
<2342EFEC-782B-44EE...@microsoft.com>
<p#EXQ6uyF...@TK2MSFTNGXA01.phx.gbl>

<0C8C8CA2-70E2-4DC6...@microsoft.com>
<6PeB7mT...@TK2MSFTNGXA02.phx.gbl>
<33DDAAC2-0516-4404...@microsoft.com>
<nJDXpDgz...@TK2MSFTNGXA02.phx.gbl>


| Subject: RE: formview control question

| Date: Tue, 11 Oct 2005 09:40:02 -0700
| Lines: 43
| Message-ID: <A5190B5A-D49A-4090...@microsoft.com>


| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250

| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:30573
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

TdarTdar

unread,
Oct 12, 2005, 11:18:03 AM10/12/05
to
Thanks,
Frankly there should be more detailed Training, If i had a video that
details all the ways to work with a control, I don't think we would have
had to go thru this. I really thanks you for your time, This is going to
help Big Time...

Steven Cheng[MSFT]

unread,
Oct 12, 2005, 9:55:39 PM10/12/05
to
You're welcome David,

BTW, if you have interest, you can have a look at the tutorial on the
beta.asp.net site which contains lots of samples there.

Thanks & 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.)


--------------------
| Thread-Topic: formview control question

| thread-index: AcXPQCQNVDwpCSZqTqe/dyy7Wvi3JA==
| X-WBNR-Posting-Host: 65.35.95.11


| From: "=?Utf-8?B?VGRhclRkYXI=?=" <Td...@noemail.nospam>
| References: <320E0B58-3629-44D7...@microsoft.com>
<2xJWmWly...@TK2MSFTNGXA01.phx.gbl>
<2342EFEC-782B-44EE...@microsoft.com>
<p#EXQ6uyF...@TK2MSFTNGXA01.phx.gbl>
<0C8C8CA2-70E2-4DC6...@microsoft.com>
<6PeB7mT...@TK2MSFTNGXA02.phx.gbl>
<33DDAAC2-0516-4404...@microsoft.com>
<nJDXpDgz...@TK2MSFTNGXA02.phx.gbl>

<A5190B5A-D49A-4090...@microsoft.com>
<zrGcY4sz...@TK2MSFTNGXA02.phx.gbl>


| Subject: RE: formview control question

| Date: Wed, 12 Oct 2005 08:18:03 -0700
| Lines: 117
| Message-ID: <670C966C-F2F4-4C25...@microsoft.com>


| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250

| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:30586
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

0 new messages