473,857 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Repeater.ItemIn dex

I am trying to make a "tabbed" interface by iterating through a dataset with
a conditional statement. For example:

----------------------------------------------------------------------------------------------------------------------
| <a href="config.as px?siteid=FIEJG IE">Site 1</a| Site 2 | <a
href="config.as px?siteid=DFOWE MF">Site 3</a>|

In the example above site 2 is the "current" tab.

I have the following code at the top of my aspx page:

protected string GenerateTabLink (string SiteID) {
string strSiteID = SiteID;
int intSiteNum = tabs_repeater.I temIndex;

System.Text.Str ingBuilder strLink = new
System.Text.Str ingBuilder();

if (strSiteID == Request.QuerySt ring["siteid"]){
strLink.Append( "Site ");
strLink.Append( intSiteNum + 1);
} else {
strLink.Append( "<a
href=\"tabpage. aspx?siteid=");
strLink.Append( Eval("site_id") );
strLink.Append( "\">Site ");
strLink.Append( intSiteNum + 1);
strLink.Append( "</a>");
}
return strLink.ToStrin g();
}

<..... Later in the page .....>

<ASP:Repeater id="tabs_repeat er" DataSourceID="t abs_repeater_da tasource"
runat="server">
<HeaderTemplate >
</HeaderTemplate>
<ItemTemplate >
<li><%#Generate TabLink(Eval("s ite_id"))%></li>
</ItemTemplate>
<FooterTemplate >
</FooterTemplate>
</ASP:Repeater>
I'm getting an error message indicating: The name 'tabs_repeater' does not
exist in the current context

I've also tried passing "tabs_repeater. ItemIndex" as a parameter to the
function with no luck also. Could anyone clue me in on what my problem is
and/or how I can get this working?

Thanks in advance,
Brad
Feb 25 '07 #1
5 3870
Hello Brad,

Based on your description and the code snippet, you're building a custom
function to generate some dynamic html fragment that need to embed in each
repeater item(based on the item's ItemIndex) ,correct?

The problem you met here is due to the "ItemIndex" is not a property of
Repeater control, but of RepeaterItem control. To reference ItemIndex, you
need to get the reference to the RepeaterItem (of each row). For such
scenario, I think you should use either of the following means:

1. You can add a paramter on your custom helper function and pass the
ItemIndex into the function from the databinding <%# %expression. e.g.

=====helper function======= ===
protected string GetTemplate(int index)
{
return "index: " + index;
}

======repeater template======= =
............... .....
<ItemTemplate >
<br /><hr /><br />
<%# GetTemplate(Con tainer.ItemInde x) %>
</ItemTemplate>
</asp:Repeater>
=============== =====
#you can find some other useful property on the "Container" object
2. Or you can use the Repeater.ItemCr eated event to programamticall y add
custom sub controls .e.g.

========repeate r tempalte======= ======
<ItemTemplate >
<br /><hr /><br />
subcontrols:<br />
<asp:PlaceHolde r ID="holder" runat="server"> </asp:PlaceHolder >

</ItemTemplate>
</asp:Repeater>

========ItemCre ated event========== =
protected void Repeater1_ItemC reated(object sender, RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
PlaceHolder holder = e.Item.FindCont rol("holder") as
PlaceHolder;

LiteralControl control = new LiteralControl( );
control.Text = "<br/><a href=\"#\"ItemI ndex: " +
e.Item.ItemInde x + "</a>" ;

holder.Controls .Add(control);

}
}
=============== =============== ====

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 26 '07 #2
Steven -

Thanks for your post. I think you understand what I am trying to accomplish
but neither of your examples completely encompass what I'm trying to
achieve. I have tried to apply your examples to my code but I'm not having
much luck. (Please bear in mind I'm a ASP.net/C# novice) :-)

I am actually trying to work with two variables - SiteNum and SiteID.

SiteNum - is a numeric value between 1 and n. This value should be set to
Container.ItemI ndex. This value is not stored in any databases - it's just
for display purposes to differentiate the tabs.

SiteID - is an alphanumeric value which is obtained through a database
record populated by the repeater datasource. Its used in forming the actual
hyperlink.

I need to combine both variables to produce a dynamic html code fragment.
So for instance the code might produce: "<a href="sdof3k45j 4">Site 1</a>"
(sans quotes) Or it might produce: "Site 1" (without a link) It all depends
on if SiteID of the current record matches Request.QuerySt ring["siteid"]).

In the first example you provided it looks like your only outputting the
SiteNum not the SiteID. I tried to combine the function you provided into my
existing function with no luck:

====== Generate Tab Link Function =======

protected string GenerateTabLink (string SiteID, int SiteNum) {
string strSiteID = SiteID;
int intSiteNum = SiteNum;

System.Text.Str ingBuilder strLink = new System.Text.Str ingBuilder();

if (strSiteID == Request.QuerySt ring["siteid"]){
strLink.Append( "Site ");
strLink.Append( intSiteNum + 1);
} else {
strLink.Append( "<a href=\"config.a spx?siteid=");
strLink.Append( Eval("site_id") );
strLink.Append( "\">Site ");
strLink.Append( intSiteNum + 1);
strLink.Append( "</a>");
}

return strLink.ToStrin g();
}
====== Repeater Template =======
<ASP:Repeater id="tabs_repeat er" DataSourceID="t abs_repeater_da tasource"
runat="server">
<HeaderTemplate >
</HeaderTemplate>
<ItemTemplate >
<li><%# GenerateTabLink ((Eval("site_id ")),Container.I temIndex) %></li>
</ItemTemplate>
<FooterTemplate >
</FooterTemplate>
</ASP:Repeater>
In the second example - it seems like your trying to populate the repeater
as its created? But beyond that I'm not sure the other code does.

I'm still wrangling with your examples but if you could provide any
additional assistance I would be very grateful.

Thank You,
Brad
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:8X******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hello Brad,

Based on your description and the code snippet, you're building a custom
function to generate some dynamic html fragment that need to embed in each
repeater item(based on the item's ItemIndex) ,correct?

The problem you met here is due to the "ItemIndex" is not a property of
Repeater control, but of RepeaterItem control. To reference ItemIndex, you
need to get the reference to the RepeaterItem (of each row). For such
scenario, I think you should use either of the following means:

1. You can add a paramter on your custom helper function and pass the
ItemIndex into the function from the databinding <%# %expression. e.g.

=====helper function======= ===
protected string GetTemplate(int index)
{
return "index: " + index;
}

======repeater template======= =
............... ....
<ItemTemplate >
<br /><hr /><br />
<%# GetTemplate(Con tainer.ItemInde x) %>
</ItemTemplate>
</asp:Repeater>
=============== =====
#you can find some other useful property on the "Container" object
2. Or you can use the Repeater.ItemCr eated event to programamticall y add
custom sub controls .e.g.

========repeate r tempalte======= ======
<ItemTemplate >
<br /><hr /><br />
subcontrols:<br />
<asp:PlaceHolde r ID="holder" runat="server"> </asp:PlaceHolder >

</ItemTemplate>
</asp:Repeater>

========ItemCre ated event========== =
protected void Repeater1_ItemC reated(object sender, RepeaterItemEve ntArgs
e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
PlaceHolder holder = e.Item.FindCont rol("holder") as
PlaceHolder;

LiteralControl control = new LiteralControl( );
control.Text = "<br/><a href=\"#\"ItemI ndex: " +
e.Item.ItemInde x + "</a>" ;

holder.Controls .Add(control);

}
}
=============== =============== ====

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.



Feb 27 '07 #3
Hello Brad,

Thanks for your reply.

For your further questions, here are my suggestion:

In the first example you provided it looks like your only outputting the
SiteNum not the SiteID. I tried to combine the function you provided into
my
existing function with no luck:
=============== ===============

Sure, you can add more parameters to the helper function and pass into
additional values if you have. As for the following expression:

<li><%# GenerateTabLink ((Eval("site_id ")),Container.I temIndex) %></li>

I don't see any problem here, the only possible issue is that the "site_id"
is not a string paramter, so that it mismatch the below function:

protected string GenerateTabLink (string SiteID, int SiteNum)

If "site_id" field is not string, you may need to use "ToString() " to
output it as string .e.g.
<li><%# GenerateTabLink ((Eval("site_id ").ToString()), Container.ItemI ndex)
%></li>
BTW, what's the exact error message you got?

In the second example - it seems like your trying to populate the repeater
as its created? But beyond that I'm not sure the other code does.
=============== =============== =
The "ItemCreate d" event will fire each time a RepeaterItem(a row in a
repeater) has been created. And we can do some customization at that time,
such as add some additional controls or adjust some existing controls in
each ItemTemplate.

#Repeater.ItemC reated Event
http://msdn2.microsoft.com/en-us/lib...trols.repeater.
itemcreated(VS. 71).aspx

I mentioned this event is because what you want to is more like add some
additional controls into "RepeaterIt em" dynamically rather than display
some text through databinding. Therefore, using <%# %expression to output
html markup is not quite recommended. If posible, you're prefered to use
ItemCreated event for adding additional controls into RepeaterItem.
Please feel free to let me know if you have any more specific questions,
I'd be glad to assist.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Feb 27 '07 #4
Steven -

You were spot on - all my problems revolved around the fact that siteid was
not a string - it was a GUID containing letters, numbers and dashes. I
stripped the dashes out and my code runs perfectly now. I owe you a debit of
gratitude - thank you so much!

Best Regards,
Brad Baker
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:%2******** ********@TK2MSF TNGHUB02.phx.gb l...
Hello Brad,

Thanks for your reply.

For your further questions, here are my suggestion:

In the first example you provided it looks like your only outputting the
SiteNum not the SiteID. I tried to combine the function you provided into
my
existing function with no luck:
=============== ===============

Sure, you can add more parameters to the helper function and pass into
additional values if you have. As for the following expression:

<li><%# GenerateTabLink ((Eval("site_id ")),Container.I temIndex) %></li>

I don't see any problem here, the only possible issue is that the
"site_id"
is not a string paramter, so that it mismatch the below function:

protected string GenerateTabLink (string SiteID, int SiteNum)

If "site_id" field is not string, you may need to use "ToString() " to
output it as string .e.g.
<li><%# GenerateTabLink ((Eval("site_id ").ToString()), Container.ItemI ndex)
%></li>
BTW, what's the exact error message you got?

In the second example - it seems like your trying to populate the repeater
as its created? But beyond that I'm not sure the other code does.
=============== =============== =
The "ItemCreate d" event will fire each time a RepeaterItem(a row in a
repeater) has been created. And we can do some customization at that time,
such as add some additional controls or adjust some existing controls in
each ItemTemplate.

#Repeater.ItemC reated Event
http://msdn2.microsoft.com/en-us/lib...trols.repeater.
itemcreated(VS. 71).aspx

I mentioned this event is because what you want to is more like add some
additional controls into "RepeaterIt em" dynamically rather than display
some text through databinding. Therefore, using <%# %expression to
output
html markup is not quite recommended. If posible, you're prefered to use
ItemCreated event for adding additional controls into RepeaterItem.
Please feel free to let me know if you have any more specific questions,
I'd be glad to assist.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.


Mar 1 '07 #5
You're welcome :-)

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Mar 1 '07 #6

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

Similar topics

2
3306
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object reference not set to an instance of an object". This error message commonly occurs when a server control is incorrecly declared, so naturally I have double checked this. To test this, I moved the aspx code for the DataGrid ('myNestedDataGrid')...
1
2332
by: Fraggle | last post by:
I have a repeater with controls added at run time. the <template> also contains a <asp:textbox that is made visible on some repeater elements. when I come to read the text info out it has disapeared. The read is done on a button click. I can read the selected items from the other controls in the repeater, demo page here
2
1798
by: News | last post by:
Hi I need help to display and edit data in a data grid within a repeater. The code is below: Sub dgrdEvents_EditCommand(sender As Object, e As DataGridCommandEventArgs) dgrdEvents.EditItemIndex = e.Item.ItemIndex BuildList() End Sub
1
5351
by: Bryan | last post by:
I trying to figure out out to validate a textbox inside a repeater once a person presses a button on a repeater. Here's the validation Code behind: Please be aware that line e.Item.ItemIndex is invalid. Because I don't know how to pass the repeater as the object through the OnServerValidate Tag in the ASP.NET side. What I really need is to pull the ItemIndex from the actual repeater.
3
1348
by: Roshawn Dawson | last post by:
Hi, I have a repeater control. This control will render a number of textboxes on the page. Each textbox has its onblur event wired to a JScript function. Here's a sample: <asp:textbox onblur="blip(this,<%# Container.ItemIndex %>)" text="<%#Container.DataItem("Quantity")%>" /> The binding expression included within the JScript function is giving me
7
5496
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the Repeater control, I've placed DropDownLists and CheckBoxes. When the user has updated the information, he/he clicks the submit button which is outside the scope of the Repeater control.
5
4808
by: RC- | last post by:
Hi everyone, I have been searching and searching for an answer to this question using Google and what not; I have not been able to find a "clear cut" answer. OK, now the question: I have a Repeater control that works great. What I am trying to do is perform an active count of the number of rows that the repeater is rendering. The end goal is to insert a page break after six rows of data. I cannot figure out how to count the rows one...
7
9103
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've tried several different approaches for finding the placeholder: This: MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1"); Produces this error: Object reference not set to an instance of an object.
2
1570
by: dm3281 | last post by:
Hi all -- I have a strange issue. I have obtained a scripted database and compiled ASP.NET 2.0 application from a sister site that I'm trying to implement locally. I have successfully created the database and accessed various ASP.NET 2.0 admin web pages for populating some of the fields. The issue is, on one particular page that has two dropdown listboxes, where second was is populated with a list of customer numbers after the...
0
9768
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10711
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.