From: Mr. Arnold on
David C wrote:
> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
> news:eqy67vUaKHA.5544(a)TK2MSFTNGP02.phx.gbl...
>> David C wrote:
>>> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
>>> news:%23W3oDQUaKHA.1592(a)TK2MSFTNGP06.phx.gbl...
>>>> David C wrote:
>>>>> Is there a way to loop through all TextBox controls of a FormView and
>>>>> blank them out? Thanks.
>>>>>
>>>>> David
>>>> Yes, you can loop through all the controls on the Web from, check what
>>>> type of UI control object it is, and address the properties of the UI
>>>> control object.
>>>>
>>>> ctrl.Text = "" if the control has a Text property, as an example.
>>>>
>>>> http://dotnetcoderoom.wordpress.com/2009/03/07/traverse-loop-through-all-form-controls-in-aspnet/
>>> I tried the link (it was in C# and I use VB) and created the sub below,
>>> but it does not seem to work as after running it the controls still have
>>> data. Can you see any problems? Thanks.
>>>
>>> David
>>>
>>> Private Sub ClearForm()
>>> Dim fv As FormView = fvPeople
>>> Dim tb As TextBox
>>> For Each ctrl As System.Web.UI.Control In fvPeople.Controls
>>> If TypeOf ctrl Is TextBox Then
>>> tb = ctrl
>>> tb.Text = ""
>>> End If
>>> Next
>>> End Sub
>> I mislead you. The example I gave you was loop on a Web form not a
>> FormView.
>>
>>
>> You may still need a loop using the FormView.FindControl.
>>
>> http://geekswithblogs.net/azamsharp/archive/2006/05/22/79294.aspx
>>
>> HTH
>
> Sorry, this does not help me. I know how to loop through a single control
> like a listbox. I need to loop through all controls in a FormView. Thanks.
>
> David
>
>

A FormView is a databound control based on rows like a table, right?

If it were me, I would find a way to loop through the table rows, find
the control, an object, I was looking for on the row using
FV.FindControl(), and address the object's properties. Having not worked
with a FV, I would suspect that is the way it must be done.

The example provided shows you how to find the control on the FV. It's
up to you to think outside of the box and find a way to implement the
solution to address the problem.


From: David C on

"Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
news:u5PCDOVaKHA.428(a)TK2MSFTNGP06.phx.gbl...
> David C wrote:
>> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
>> news:eqy67vUaKHA.5544(a)TK2MSFTNGP02.phx.gbl...
>>> David C wrote:
>>>> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
>>>> news:%23W3oDQUaKHA.1592(a)TK2MSFTNGP06.phx.gbl...
>>>>> David C wrote:
>>>>>> Is there a way to loop through all TextBox controls of a FormView and
>>>>>> blank them out? Thanks.
>>>>>>
>>>>>> David
>>>>> Yes, you can loop through all the controls on the Web from, check what
>>>>> type of UI control object it is, and address the properties of the UI
>>>>> control object.
>>>>>
>>>>> ctrl.Text = "" if the control has a Text property, as an example.
>>>>>
>>>>> http://dotnetcoderoom.wordpress.com/2009/03/07/traverse-loop-through-all-form-controls-in-aspnet/
>>>> I tried the link (it was in C# and I use VB) and created the sub below,
>>>> but it does not seem to work as after running it the controls still
>>>> have data. Can you see any problems? Thanks.
>>>>
>>>> David
>>>>
>>>> Private Sub ClearForm()
>>>> Dim fv As FormView = fvPeople
>>>> Dim tb As TextBox
>>>> For Each ctrl As System.Web.UI.Control In fvPeople.Controls
>>>> If TypeOf ctrl Is TextBox Then
>>>> tb = ctrl
>>>> tb.Text = ""
>>>> End If
>>>> Next
>>>> End Sub
>>> I mislead you. The example I gave you was loop on a Web form not a
>>> FormView.
>>>
>>>
>>> You may still need a loop using the FormView.FindControl.
>>>
>>> http://geekswithblogs.net/azamsharp/archive/2006/05/22/79294.aspx
>>>
>>> HTH
>>
>> Sorry, this does not help me. I know how to loop through a single
>> control like a listbox. I need to loop through all controls in a
>> FormView. Thanks.
>>
>> David
>
> A FormView is a databound control based on rows like a table, right?
>
> If it were me, I would find a way to loop through the table rows, find the
> control, an object, I was looking for on the row using FV.FindControl(),
> and address the object's properties. Having not worked with a FV, I would
> suspect that is the way it must be done.
>
> The example provided shows you how to find the control on the FV. It's up
> to you to think outside of the box and find a way to implement the
> solution to address the problem.
>
>
Actually, a FormView is a single-row control and not a grid/table.

I got my code to work ok now. I was setting the FormView control to
visible=False and it did not work. I changed it to a CSSClass that was
hidden and it worked. Below is my finished code, if interested.

Private Sub ClearForm()
Dim tb As TextBox
Dim ctrl As Control
For Each ctrl In fvPeople.Controls
If TypeOf ctrl Is TextBox Then
tb = ctrl
tb.Text = ""
End If
Next

End Sub


From: Mr. Arnold on
David C wrote:
> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
> news:u5PCDOVaKHA.428(a)TK2MSFTNGP06.phx.gbl...
>> David C wrote:
>>> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
>>> news:eqy67vUaKHA.5544(a)TK2MSFTNGP02.phx.gbl...
>>>> David C wrote:
>>>>> "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
>>>>> news:%23W3oDQUaKHA.1592(a)TK2MSFTNGP06.phx.gbl...
>>>>>> David C wrote:
>>>>>>> Is there a way to loop through all TextBox controls of a FormView and
>>>>>>> blank them out? Thanks.
>>>>>>>
>>>>>>> David
>>>>>> Yes, you can loop through all the controls on the Web from, check what
>>>>>> type of UI control object it is, and address the properties of the UI
>>>>>> control object.
>>>>>>
>>>>>> ctrl.Text = "" if the control has a Text property, as an example.
>>>>>>
>>>>>> http://dotnetcoderoom.wordpress.com/2009/03/07/traverse-loop-through-all-form-controls-in-aspnet/
>>>>> I tried the link (it was in C# and I use VB) and created the sub below,
>>>>> but it does not seem to work as after running it the controls still
>>>>> have data. Can you see any problems? Thanks.
>>>>>
>>>>> David
>>>>>
>>>>> Private Sub ClearForm()
>>>>> Dim fv As FormView = fvPeople
>>>>> Dim tb As TextBox
>>>>> For Each ctrl As System.Web.UI.Control In fvPeople.Controls
>>>>> If TypeOf ctrl Is TextBox Then
>>>>> tb = ctrl
>>>>> tb.Text = ""
>>>>> End If
>>>>> Next
>>>>> End Sub
>>>> I mislead you. The example I gave you was loop on a Web form not a
>>>> FormView.
>>>>
>>>>
>>>> You may still need a loop using the FormView.FindControl.
>>>>
>>>> http://geekswithblogs.net/azamsharp/archive/2006/05/22/79294.aspx
>>>>
>>>> HTH
>>> Sorry, this does not help me. I know how to loop through a single
>>> control like a listbox. I need to loop through all controls in a
>>> FormView. Thanks.
>>>
>>> David
>> A FormView is a databound control based on rows like a table, right?
>>
>> If it were me, I would find a way to loop through the table rows, find the
>> control, an object, I was looking for on the row using FV.FindControl(),
>> and address the object's properties. Having not worked with a FV, I would
>> suspect that is the way it must be done.
>>
>> The example provided shows you how to find the control on the FV. It's up
>> to you to think outside of the box and find a way to implement the
>> solution to address the problem.
>>
>>
> Actually, a FormView is a single-row control and not a grid/table.
>
> I got my code to work ok now. I was setting the FormView control to
> visible=False and it did not work. I changed it to a CSSClass that was
> hidden and it worked. Below is my finished code, if interested.
>
> Private Sub ClearForm()
> Dim tb As TextBox
> Dim ctrl As Control
> For Each ctrl In fvPeople.Controls
> If TypeOf ctrl Is TextBox Then
> tb = ctrl
> tb.Text = ""
> End If
> Next
>
> End Sub
>
>

I am glad it worked out for you.
From: Mark Rae [MVP] on
"David C" <dlchase(a)lifetimeinc.com> wrote in message
news:%23RsTzUVaKHA.2188(a)TK2MSFTNGP04.phx.gbl...

> I was setting the FormView control to visible=False and it did not work. I
> changed it to a CSSClass that was hidden and it worked.

That is because when any server-side's control's Visible property is set to
"false", it doesn't actually get rendered in the HTML streamed down to the
client...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

First  |  Prev  | 
Pages: 1 2
Prev: Find Control in Silverlight
Next: gridview in gridview