472,779 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 2285
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.