Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing a Control inside a Repeater from a code behind file

Reply
Thread Tools

Accessing a Control inside a Repeater from a code behind file

 
 
Ric
Guest
Posts: n/a
 
      02-27-2004
im new to asp.net. please help if u can.
is it possible to refer to a control(ie lable, placeholder, textbox)
that is inside a repeater object from a code behind file? when i place
the control object outside of the repeater, i can refer to it from the
code behind file. when i place the control object inside the repeater,
i get a 'need to instanciate the control object' error. if i declare
the control object inside the control behind file, the error goes
away, but i cant refer to the control objects components. please help.
 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      02-27-2004
Hi, Ric,

The following article explains how it is done:

http://msdn.microsoft.com/library/en...formspages.asp

Hope this helps
Martin
"Ric" <> wrote in message
news: om...
> im new to asp.net. please help if u can.
> is it possible to refer to a control(ie lable, placeholder, textbox)
> that is inside a repeater object from a code behind file? when i place
> the control object outside of the repeater, i can refer to it from the
> code behind file. when i place the control object inside the repeater,
> i get a 'need to instanciate the control object' error. if i declare
> the control object inside the control behind file, the error goes
> away, but i cant refer to the control objects components. please help.



 
Reply With Quote
 
 
 
 
ric carrasquilla
Guest
Posts: n/a
 
      02-27-2004


thx martin. i really appreciate the help. i'll bookmark this site.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Ric
Guest
Posts: n/a
 
      03-01-2004
thx again for the help martin. i was able to use your suggestion to
get to the control within the repeater. also, i was able to understand
a bit more bout objects, events and arguments. but, im sure i have a
lot to more to learn.

if u or someone else can help me with another question, please do.

i have a repeater pulling job information from a database. each
repeater itemtemplate has with a linkbutton and a row with a label
(for now).

<asp:repeater ID="EmployeeInfo" OnItemCommand="getActivityList"
runat="server">

<itemtemplate>
<tr bgcolor="#CCCCCC">
<td><%# Container.DataItem(0)%></td>
<td><%# Container.DataItem(1)%></td>
<td><%# Container.DataItem(2)%></td>
<td><%# Container.DataItem(3)%></td>
<td><%# Container.DataItem(4)%></td>
<td><asp:linkbutton Text=<%# Container.DataItem(5)%>
runat="server"/></td>
</tr>
<tr>
<td><asp:label id="litLabel" Runat="Server" Text="labelti"
Visible="false"/></td>
</tr>
</itemtemplate>

when u click on the linkbutton, the label(eventually it will be a
placeholder with more database info in another repeater) will become
visible with detailed info bout the job.

the first Container.DataItem(0) has an ID number that I need to
extract and send to the stored procedure. how can i extract that
dataItem. ive been able to loop throw the items in the repeater item
and extract the entire row. i tried to convert that info to a
DataBoundLiteralControl and pull the text from it. but when i tried to
use string functions to pull the ID number or even get a length of
string i could not consistently get what i needed. i figured out that
row is coded with <html> table and row tags. thus, im back to trying
to get the data from the first container.dataitem. so, to make a long
request even longer, what object or class do i use to pull individual
dataitems from an item. i looked at the dataitem property from
repeateritem class, but i cant get it to work. again, thx for the
help.
 
Reply With Quote
 
Martin Dechev
Guest
Posts: n/a
 
      03-01-2004
Hi, Ric,

You can pass this value in the CommandName or CommandArgument property:

> <asp:repeater ID="EmployeeInfo" OnItemCommand="getActivityList"
> runat="server">
>
> <itemtemplate>
> <tr bgcolor="#CCCCCC">
> <td><%# Container.DataItem(0)%></td>
> <td><%# Container.DataItem(1)%></td>
> <td><%# Container.DataItem(2)%></td>
> <td><%# Container.DataItem(3)%></td>
> <td><%# Container.DataItem(4)%></td>
> <td><asp:linkbutton Text='<%# Container.DataItem(5)%>'


CommandName="ShowDetails"
CommandArgument='<%# Container.DataItem(0)%>'

> runat="server"/></td>
> </tr>
> <tr>
> <td><asp:label id="litLabel" Runat="Server" Text="labelti"
> Visible="false"/></td>
> </tr>
> </itemtemplate>


If the ID is an integer you will have to parse it:

[C#]
protected void getActivityList(object s, RepeaterCommandEventArgs e)
{
if(e.CommandName == "ShowDetails")
{
int ID = int.Parse(e.CommandArgument);
//....
}
}

[VB.NET]
Protected Sub getActivityList(s As Object, e As RepeaterCommandEventArgs)
If e.CommandName = "ShowDetails" Then
Dim ID As Int32 = Int32.Parse(e.CommandArgument)
'....
End If
End Sub

Hope this helps
Martin


 
Reply With Quote
 
ric carrasquilla
Guest
Posts: n/a
 
      03-01-2004

thx again for the help martin. just curiously, if u had to send more
than one command arguement how would u do that? i used a commandName and
commandArgument and wondered what would u do to send two
commandArguments with one commandName or two commandNames each with a
commandArgument.

thx again for the push in the right direction.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Martin Dechev
Guest
Posts: n/a
 
      03-01-2004
Hi, ric carrasquilla,

<snip>

> just curiously, if u had to send more
> than one command arguement how would u do that?


You normally don't need to do that. The common design is to identify your
objects with a single identifier. It is possible to pass 2 parameters
anyway - one for the action and another for the object identifier. This is
how it was designed, this is how it works and I believe it is enough for any
case.

Greetings
Martin


 
Reply With Quote
 
ric carrasquilla
Guest
Posts: n/a
 
      03-01-2004


thx again martin. i really appreciate the time and thoroughness of your
answers. have a good day.

ric

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Monika Mesik
Guest
Posts: n/a
 
      03-03-2004
I'd like to know which site helped to answer the question. I have a similar
issue. Can you provide the link?

TIA


"ric carrasquilla" <> wrote in message
news:OwDRKdX$...
>
>
> thx martin. i really appreciate the help. i'll bookmark this site.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
ric carrasquilla
Guest
Posts: n/a
 
      03-03-2004


this is the link to how to find an object inside a repeater

http://msdn.microsoft.com/library/de.../en-us/vbcon/h
tml/vbtskreferencingcontrolsinwebformspages.asp

i hope this helps. also, if u look at the thread, martin explains how
to send a commandname and command argument to the repeatercommandevent

please reply to this thread for more help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RowCommand: accessing ObjectDataSource from inside gridview inside a repeater? HockeyFan ASP .Net 1 07-04-2007 05:49 AM
Tough Question: Accessing controls inside inline template in a user control, in a repeater Dave ASP .Net 1 12-22-2006 12:58 PM
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
Accessing TextBox/Label controls inside a Repeater control Ashish Bandi via .NET 247 ASP .Net Web Controls 1 05-14-2004 07:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57