468,278 Members | 1,567 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,278 developers. It's quick & easy.

Regex inside of a tag

Is there a way to use Regex inside of a tag, such as asp:label?

I tried something like this but can't make it work:

<asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")
%>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>

I have this inside my Repeater and want it to filter the field during bind.
I can do it afterwards by just looping through the repeater items, but that
is extra work and time.

Thanks,

Tom
Nov 19 '05 #1
6 1532
try wrapping it around the Container.DataItem("Phone") section, rather than
the text section
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <tf*@dslextreme.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Is there a way to use Regex inside of a tag, such as asp:label?

I tried something like this but can't make it work:

<asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")
%>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>

I have this inside my Repeater and want it to filter the field during
bind.
I can do it afterwards by just looping through the repeater items, but
that
is extra work and time.

Thanks,

Tom

Nov 19 '05 #2

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
try wrapping it around the Container.DataItem("Phone") section, rather
than the text section
I thought that was what I was doing? Did I miss something?

Tom

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <tf*@dslextreme.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Is there a way to use Regex inside of a tag, such as asp:label?

I tried something like this but can't make it work:

<asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")
%>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>

I have this inside my Repeater and want it to filter the field during
bind.
I can do it afterwards by just looping through the repeater items, but
that
is extra work and time.

Thanks,

Tom


Nov 19 '05 #3

meaning

<asp:label id="Phone" text='<%# Regex.Replace(Container.DataItem("Phone")
,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>

Sreejith

"tshad" wrote:

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
try wrapping it around the Container.DataItem("Phone") section, rather
than the text section


I thought that was what I was doing? Did I miss something?

Tom


--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <tf*@dslextreme.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Is there a way to use Regex inside of a tag, such as asp:label?

I tried something like this but can't make it work:

<asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")
%>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>

I have this inside my Repeater and want it to filter the field during
bind.
I can do it afterwards by just looping through the repeater items, but
that
is extra work and time.

Thanks,

Tom



Nov 19 '05 #4
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...

meaning

<asp:label id="Phone" text='<%# Regex.Replace(Container.DataItem("Phone")
,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>

That worked great.

Here is what I was doing it. I first get the data in my Repeater:

<asp:label ID="Wages" text='<%#
Regex.Replace(Container.DataItem("Wages"),"\-|\,",""),"(\d{3})(\d{3})(\d{4})
","($1) $2-$3" %>' runat="server"/>
Then I go through the RepeaterItem list and filter the phone numbers.

for each oItem as RepeaterItem in ExperienceRepeater.items
oLabel = Ctype(oItem.FindControl("Phone"),Label)
oLabel.Text = Regex.Replace(Regex.Replace(oLabel.Text,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")
next

If I replace the Regex line into the Repeater, as you show:

<asp:label ID="Wages" text='<%#
Regex.Replace(Regex.Replace(Container.DataItem("Ph one"),"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3" %>' runat="server"/>

It works fine.

What about a BoundColumn?

I tried changing my Bound Column:

<asp:BoundColumn DataField=ContactPhone
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

and replaced it with:

<asp:BoundColumn DataField='Regex.Replace(Regex.Replace(ContactPhon e,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")'
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

but got the error:

A field or property with the name
'Regex.Replace(Regex.Replace(ContactPhone,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")' was not found on the selected
datasource.

Do I have to use a TemplateColumn and use an asp:Label?

Thanks,

Tom
Sreejith

"tshad" wrote:

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
try wrapping it around the Container.DataItem("Phone") section, rather
than the text section


I thought that was what I was doing? Did I miss something?

Tom


--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <tf*@dslextreme.com> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
> Is there a way to use Regex inside of a tag, such as asp:label?
>
> I tried something like this but can't make it work:
>
> <asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")> %>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>
>
> I have this inside my Repeater and want it to filter the field during
> bind.
> I can do it afterwards by just looping through the repeater items, but> that
> is extra work and time.
>
> Thanks,
>
> Tom
>
>



Nov 19 '05 #5
<asp:BoundColumn DataField='Regex.Replace(Regex.Replace(ContactPhon e,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")'
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">
Above wouldnt work.. wrong usage..
I believe, you will be able to create a TemplateColumn as below

<asp:TemplateColumn>

<ItemTemplate>
<asp:label id="Phone" text='<%#
Regex.Replace(Container.DataItem("Phone")
,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>
</ItemTemplate>

<asp:TemplateColumn>
Sreejith


"tshad" wrote:
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...

meaning

<asp:label id="Phone" text='<%# Regex.Replace(Container.DataItem("Phone")
,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>


That worked great.

Here is what I was doing it. I first get the data in my Repeater:

<asp:label ID="Wages" text='<%#
Regex.Replace(Container.DataItem("Wages"),"\-|\,",""),"(\d{3})(\d{3})(\d{4})
","($1) $2-$3" %>' runat="server"/>
Then I go through the RepeaterItem list and filter the phone numbers.

for each oItem as RepeaterItem in ExperienceRepeater.items
oLabel = Ctype(oItem.FindControl("Phone"),Label)
oLabel.Text = Regex.Replace(Regex.Replace(oLabel.Text,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")
next

If I replace the Regex line into the Repeater, as you show:

<asp:label ID="Wages" text='<%#
Regex.Replace(Regex.Replace(Container.DataItem("Ph one"),"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3" %>' runat="server"/>

It works fine.

What about a BoundColumn?

I tried changing my Bound Column:

<asp:BoundColumn DataField=ContactPhone
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

and replaced it with:

<asp:BoundColumn DataField='Regex.Replace(Regex.Replace(ContactPhon e,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")'
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

but got the error:

A field or property with the name
'Regex.Replace(Regex.Replace(ContactPhone,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")' was not found on the selected
datasource.

Do I have to use a TemplateColumn and use an asp:Label?

Thanks,

Tom
Sreejith

"tshad" wrote:

"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> try wrapping it around the Container.DataItem("Phone") section, rather
> than the text section

I thought that was what I was doing? Did I miss something?

Tom
>
>
> --
> Regards
>
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
>
> "tshad" <tf*@dslextreme.com> wrote in message
> news:ep**************@tk2msftngp13.phx.gbl...
>> Is there a way to use Regex inside of a tag, such as asp:label?
>>
>> I tried something like this but can't make it work:
>>
>> <asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone") >> %>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>
>>
>> I have this inside my Repeater and want it to filter the field during
>> bind.
>> I can do it afterwards by just looping through the repeater items, but >> that
>> is extra work and time.
>>
>> Thanks,
>>
>> Tom
>>
>>
>
>


Nov 19 '05 #6
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:58**********************************@microsof t.com...
<asp:BoundColumn DataField='Regex.Replace(Regex.Replace(ContactPhon e,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")'
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">
Above wouldnt work.. wrong usage..
I believe, you will be able to create a TemplateColumn as below


You're right.

That seems to be the case. I found that since I have been leaning more
towards formatting on the client side, that I making more use of the
templateColumn and less of the BoundColumn.

Thanks,

Tom
<asp:TemplateColumn>

<ItemTemplate>
<asp:label id="Phone" text='<%#
Regex.Replace(Container.DataItem("Phone")
,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>
</ItemTemplate>

<asp:TemplateColumn>
Sreejith


"tshad" wrote:
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
>
> meaning
>
> <asp:label id="Phone" text='<%#
> Regex.Replace(Container.DataItem("Phone")
> ,"(\d{3})(\d{3})(\d{4})","($1) $2-$3") %>' runat="server"/>
>


That worked great.

Here is what I was doing it. I first get the data in my Repeater:

<asp:label ID="Wages" text='<%#
Regex.Replace(Container.DataItem("Wages"),"\-|\,",""),"(\d{3})(\d{3})(\d{4})
","($1) $2-$3" %>' runat="server"/>
Then I go through the RepeaterItem list and filter the phone numbers.

for each oItem as RepeaterItem in ExperienceRepeater.items
oLabel = Ctype(oItem.FindControl("Phone"),Label)
oLabel.Text = Regex.Replace(Regex.Replace(oLabel.Text,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")
next

If I replace the Regex line into the Repeater, as you show:

<asp:label ID="Wages" text='<%#
Regex.Replace(Regex.Replace(Container.DataItem("Ph one"),"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3" %>' runat="server"/>

It works fine.

What about a BoundColumn?

I tried changing my Bound Column:

<asp:BoundColumn DataField=ContactPhone
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

and replaced it with:

<asp:BoundColumn
DataField='Regex.Replace(Regex.Replace(ContactPhon e,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")'
HeaderText="Phone"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"
SortExpression="ContactPhone">

but got the error:

A field or property with the name
'Regex.Replace(Regex.Replace(ContactPhone,"\-|\
",""),"(\d{3})(\d{3})(\d{4})","($1) $2-$3")' was not found on the
selected
datasource.

Do I have to use a TemplateColumn and use an asp:Label?

Thanks,

Tom
> Sreejith
>
> "tshad" wrote:
>
> >
> > "John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
> > news:%2****************@TK2MSFTNGP15.phx.gbl...
> > > try wrapping it around the Container.DataItem("Phone") section,
> > > rather
> > > than the text section
> >
> > I thought that was what I was doing? Did I miss something?
> >
> > Tom
> > >
> > >
> > > --
> > > Regards
> > >
> > > John Timney
> > > ASP.NET MVP
> > > Microsoft Regional Director
> > >
> > > "tshad" <tf*@dslextreme.com> wrote in message
> > > news:ep**************@tk2msftngp13.phx.gbl...
> > >> Is there a way to use Regex inside of a tag, such as asp:label?
> > >>
> > >> I tried something like this but can't make it work:
> > >>
> > >> <asp:label id="Phone" text=Regex.Replace('<%#

Container.DataItem("Phone")
> > >> %>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/>
> > >>
> > >> I have this inside my Repeater and want it to filter the field
> > >> during
> > >> bind.
> > >> I can do it afterwards by just looping through the repeater items,

but
> > >> that
> > >> is extra work and time.
> > >>
> > >> Thanks,
> > >>
> > >> Tom
> > >>
> > >>
> > >
> > >
> >
> >
> >


Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by JS | last post: by
5 posts views Thread by Chris | last post: by
13 posts views Thread by Chris Lieb | last post: by
4 posts views Thread by Marcus | last post: by
2 posts views Thread by natebruneau | last post: by
reply views Thread by zattat | last post: by
1 post views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.