473,387 Members | 1,882 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,387 software developers and data experts.

javascript referencing items within a Repeater?

Yesterday, I posted a question dealing with an issue of trying to
reference (from javascript on the client side) an item within a
Repeater. My code was hard-coded to use the actual ClientId, but
someone admonished me, stating that I shouldn't do that because the id
could change. However, since I'm trying to reference a control on a
Repeater line, I'm wondering how else to do that. Repeaters aren't
rendered in html are they? What method do other .Net developers use
to reference a control on a RepeaterItem when doing it from javascript?

Aug 2 '07 #1
2 5528
Hi,

Repeaters do render but what you have specified them to. Pij t is to
generate the script to access the controls on repeaterItem, at least
generate an js array which contains the ClientIDs of the controls in the
repeater

It can be done for example iterating Repeater's Items collection, calling
FindControl against every RepeaterItem to get reference to the control on
the item. Then you can access ClientID of these controls

I have availbale a sample which deals with gridView but idea is 100% same.
item type is just RepeaterItem and you iterate Repeater's Items collection

protected void GridView1_PreRender(object sender, EventArgs e)
{
StringBuilder sbScript = new StringBuilder();

//I'm doing this in PreRender because RowDataBound happens only
when databinding occurs - not necessarily on every request
//and RowCreated is too early to get the correct client-side ID
foreach(GridViewRow row in GridView1.Rows)
{
CheckBox CheckBox1 = (CheckBox)row.FindControl("CheckBox1");
sbScript.Append("'");
sbScript.Append(CheckBox1.ClientID);
sbScript.Append("'");
if(row.RowIndex != (GridView1.Rows.Count - 1))
sbScript.Append(",");

}
//Register the array
Page.ClientScript.RegisterArrayDeclaration("checkB oxes",
sbScript.ToString());
}.

Previous examplöe creates a javascript array named checkBoxes cointaining
reference of CheckBoxes with CheckBox1 on every GridViewRow. You can then
use these array at client to reference the checkboxes there.
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"HockeyFan" <le**********@gmail.comwrote in message
news:11*********************@m37g2000prh.googlegro ups.com...
Yesterday, I posted a question dealing with an issue of trying to
reference (from javascript on the client side) an item within a
Repeater. My code was hard-coded to use the actual ClientId, but
someone admonished me, stating that I shouldn't do that because the id
could change. However, since I'm trying to reference a control on a
Repeater line, I'm wondering how else to do that. Repeaters aren't
rendered in html are they? What method do other .Net developers use
to reference a control on a RepeaterItem when doing it from javascript?

Aug 2 '07 #2
Outstanding. Thanx
Aug 2 '07 #3

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

Similar topics

1
by: Mark Fox | last post by:
Hello, I have a repeater and in each itemtemplate I have a radiobuttonlist. I am attempting to figure out how on postback I could iterate through the rows displayed by the repeater and for...
2
by: Antoine | last post by:
I would like to construct my own list of items in a grid/ table/ item list layout but I have a problem. I want to add a sort of index row based on time, such as there might be blank values. Sure...
0
by: rwoo_98 | last post by:
I am using a repeater, with 3 columns of textboxes with X number of rows. The first two columns are enabled and allows the user to enter in numeric data. The third column contains the sum of the...
1
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small,...
6
by: Oscar | last post by:
I want to add items to a dropdownlist control within a Javascript eventhandler. This is what I code : var dd = document.getElementById("DropDownList1"); dd.Items.Add("1990");...
4
by: wrytat | last post by:
I've a big problem that I don't know how to solve for quite long. In one of my aspx file, I have a form that run at server. Within this form, there's a table. The first row is made up of some text...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
4
by: parsifal | last post by:
Hi everyone :-) I am learning to use the Repeater control to display a list of data. Each of my list items (or rows, however you look at it) has some child items that are 1..N in length. So I'd...
2
by: Lloyd Sheen | last post by:
I have a repeater that will have linkbuttons. I have googled much but cannot find a solution to the following. Since the items are dynamic I need to be able to attach handlers to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.