473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ItemDataBound text modification question

I've got a repeater that's bound to a datareader and I'd like to
conditionally modify the text that is being outputted. Previously, I've done
this by assigning a name to attribute to the surrounding tablecell in which
the <%# %> tags reside and I could use the findcontrol to grab a handle to
the control by name and do any necessary modifications. I'm wondering if I
can get around this? Is it necessary to assign a name to a surrounding cell?
What if I'm not using a table? I tried to use e.item.controls(0), but this
does not seem to correspond with all available controls that get databound (I
guess it excludes non web-server controls like simple client side tables),
but there seems to be only one element of type "DataBoundLiteralControl." I
was guessing that this represented the text that was between the databinding
tags, and hoped that I could modify the text property to add some text in,
but it's a read only property. To sum it up, two questions:

1, what is the DataBoundLiteralControl actually used for? What does it
represent?

2, Is there a way to do what I'd like to do? To modify the text that is
bound, without using findcontrol? (The control has no name, it's just the
contents of the <%# %> tags.

Thanks...
Jul 21 '05 #1
3 2313
Hi Benr,

Welcome to ASPNET newsgroup.
As for the problem you met in dealing with serverside databinding in
asp.net, here are some of my understanding and suggestions:

1. When we call xxcontrol.databind(); the ASP.NET will loop through all
the <%# %> blocks in that control's template and invoke them. For templated
databound control( such as datagrid, datalist, repeater..), it will loop
through all the item in datasource and executing the invocation of the <%#
%> blocks repeatly. And as for the "DataBoundLiteralControl" you
mentioned, it's the underlying internal control asp.net runtime used to
hold the databinding values generated by each
<%# %> block(this behavior is for templated databound controls like
repeater, datalist... , not for simple server controls like textbox,
label, dropdownlist....) because each templated databound control need to
add a certain control instance rather than a simple string value into its
sub controls collection.

2. For modifying the value in databinding process, we have the following
means:

1) We can use some servercontrols in the databound control's template and
assign the databiding expression to those control's property, then we can
reference those control's refernce in ItemDataBound event and modify their
corresponding propeties, just like:

<ItemTemplate>
<asp:TextBox id="txtName" runat="server" Text="<%# xxxxx %>" />
</ItemTemplate>

in ItemDataBound , we call

TextBox = e.Item.FindControl("txtName") as TextBox

to get the TextBox's reference and do our customization.

2) If we don't want to add additioal sub control to wrapper the databinding
text , one approach is to define some helper functions which do the
customization , and we can embed the function call within the <%# %> block
like:

<ItemTemplate>
<asp:TextBox id="txtName" runat="server" Text="<%#
MyFunction(DataBinder.Eval(...))%>" />
</ItemTemplate>

MyFunction can be a public/protected method of the codebebhind page class
or we can use a certain public class's static method.

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

Jul 21 '05 #2
Hey Steven,

Thanks for your response, it was exactly what I was looking for.

Sincerely,

-Ben

"Steven Cheng[MSFT]" wrote:
Hi Benr,

Welcome to ASPNET newsgroup.
As for the problem you met in dealing with serverside databinding in
asp.net, here are some of my understanding and suggestions:

1. When we call xxcontrol.databind(); the ASP.NET will loop through all
the <%# %> blocks in that control's template and invoke them. For templated
databound control( such as datagrid, datalist, repeater..), it will loop
through all the item in datasource and executing the invocation of the <%#
%> blocks repeatly. And as for the "DataBoundLiteralControl" you
mentioned, it's the underlying internal control asp.net runtime used to
hold the databinding values generated by each
<%# %> block(this behavior is for templated databound controls like
repeater, datalist... , not for simple server controls like textbox,
label, dropdownlist....) because each templated databound control need to
add a certain control instance rather than a simple string value into its
sub controls collection.

2. For modifying the value in databinding process, we have the following
means:

1) We can use some servercontrols in the databound control's template and
assign the databiding expression to those control's property, then we can
reference those control's refernce in ItemDataBound event and modify their
corresponding propeties, just like:

<ItemTemplate>
<asp:TextBox id="txtName" runat="server" Text="<%# xxxxx %>" />
</ItemTemplate>

in ItemDataBound , we call

TextBox = e.Item.FindControl("txtName") as TextBox

to get the TextBox's reference and do our customization.

2) If we don't want to add additioal sub control to wrapper the databinding
text , one approach is to define some helper functions which do the
customization , and we can embed the function call within the <%# %> block
like:

<ItemTemplate>
<asp:TextBox id="txtName" runat="server" Text="<%#
MyFunction(DataBinder.Eval(...))%>" />
</ItemTemplate>

MyFunction can be a public/protected method of the codebebhind page class
or we can use a certain public class's static method.

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

Jul 21 '05 #3
You're welcome Ben,

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

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ben R. | last post by:
I've got a repeater that's bound to a datareader and I'd like to conditionally modify the text that is being outputted. Previously, I've done this by assigning a name to attribute to the...
2
by: kscdavefl | last post by:
When I execute the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType ==...
1
by: André Almeida Maldonado | last post by:
Hey Guys, I need to manipulate the data that is binding to a datagrid BEFORE its appearance to the user. Because I need to format it inside an If Clause. I was putting my code in the...
1
by: Roy | last post by:
Hey all, This is a fairly broad question, but why is it that my datagrid hits the ItemDataBound event 3 times? Basically, I placed a response.write in all sub and functions in my codebehind and...
0
by: mplutodh1 | last post by:
I am trying to work with the ItemDataBound property of the DataList to modify the display for a page that lists future events. Here is the code: Sub OnItemDataBound(ByVal sender As Object, e As...
5
by: Nathan Sokalski | last post by:
I want to access the DataRow used in DataBinding from the ItemDataBound event. In my case, the reason for doing this is to determine whether I need to make a word singular or plural. How can I do...
4
by: Dennis E. Jones, Jr. | last post by:
I'm creating a dynamic control for each row in a REPEATER based on database values. ItemDataBound creates the control for the initial load (not postback), but I cannot get the control recreated...
5
by: Will Gillen | last post by:
I need to have a "scrolling" text label or textbox at the bottom of my window to show the URL of where a song is being played from. I want the text to scroll on a single line from left to right in...
3
by: Ben R. | last post by:
I've got a repeater that's bound to a datareader and I'd like to conditionally modify the text that is being outputted. Previously, I've done this by assigning a name to attribute to the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.