Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2006, 11:14 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to beetle54
Default

use the onItemCommand for you repeater, in the button, use the properties commandname and commandargument, give a command name and specific the argument, rememeber, this argument accepts a string, so you have to treat it like a string. use an if statement of id which button was clicked. then used onitemdatbound and capture the button argument by: e.Item.DataItem("ID"), store that into a local global variable on the page, and reference that variable in your onItemCommand. The onItemdatabound fires when the pages load, so you've capture the id when the page is load. The onItemCommand only fires when a button is clicked. I hope that helps. If you need help, [email protected]

Brandon
 
Old March 6th, 2007, 03:46 PM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I dont really know if this has been answered for you, but Ill post the down and dirty easy fixes for both of these.

First there is a fairly simple way to get a handle to anything in a repeater.

First Insert you label
---------------------------------
<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
             <asp:label id="myLabel" runat=server>
        </ItemTemplate>
</asp:Repeater>
----------------------------------
Yes its empty! It will be bound to your data.

So in your code you will call the 'bind' and link it to a data-table. I dont have time to teach you how to pull from sql or create one manually, but there are plenty of tuts out there for doing that. In this case we will assume we pulled back a datatable, and it has records in it.

private sub bindRepeater()
   dim DT as datatable 'Just so you know its a datatable
   DT = getDataTableCode() ' Returns a datatable
   repeater1.datasource = DT
   repeater1.databind()
end sub

Now this is the sub that handles databinding for htis object, that has been called automatically when you did repeater1.databind()

You will then 'find your label' on each bound row

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

   dim _label as label
   _label = e.Item.FindControl("mylabel") 'This is what we called it on aspx page

   _label.text = e.Item.DataItem("valueInDatabase") 'Current Data item in row being processed

    End Sub

That effectively binds the data, on each item bound to the appropriate row.

Now, if you want to make a 'clickable' item instead of a label, use a 'linkbutton' or 'button' or whatever.

Once you have grabbed it with

dim _myButton as new linkbutton = e.Item.FindControl("myButton")

Were assuming that 'myButton exists as an id in your repeater, and its a button, if not it will fail, and you should code for such checks, but for simplicity we wont here.

You can assign to the props.
_myButton.commandArgument = e.item.dataitem("id")
_myButton.commandName = "delete"

Now, you can catch these events through the 'repeaters item command as stated above, or you can point them to a seperate function by doing

addhandler _myButton.click, addressof mySub()

Now each time a button in the repeater is clicked it will call that sub, ASSUMING you have created the sub. It must be created just like a REAL onClick event for a button, with the same arguements passed in. Remember that the SUB / SENDER does not know its a button, so you have to tell it to have the 'buttons' exposed calls, by SETTING it to a button.


Protected Sub mySub(ByVal sender As Object, ByVal e As System.EventArgs)
   dim _myButton as linkbutton
_myButton = Sender

Now _mybutton will have the exposed items that a linkbutton has

response.write(_myButton.commandArguement)
response.write(_myButton.commandName)

End Sub


As a shorter simple solution you can bind the data, on databind, by putting in the aspx page.
<asp:label text="<%# databinder.eval(container.dataitem("DB_COL")) %>"></asp:label>

and assuming when you call databind, that DB_COL is the name of a column in the bound table, it will bind the text up for you on the fly.


The BIG benefit here is, you dont have to recompile your code, if you make the changes on the .aspx pag.

You can NOT copy and paste this code and expct it to work, as I didnt have any itellisense while doing it, and I havent checked it fully, but I wanted to give you the full breakdown on the 'dirty easy' way ppl do this.

I hope this helps you some.

Read it a couple times, it will probably give you other ideas on how to use similar controls.
 
Old April 5th, 2007, 03:17 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sandip.mis Send a message via Yahoo to sandip.mis
Default

Function Code "MyRepeaterButton_Click"?

Sandip





Similar Threads
Thread Thread Starter Forum Replies Last Post
Button OnClick problem john6630 ASP.NET 2.0 Basics 2 September 21st, 2007 05:44 PM
Button onClick Apocolypse2005 Javascript 1 November 25th, 2005 09:37 AM
Adding an OnClick procedure to repeater johno Classic ASP Databases 1 September 15th, 2005 03:36 AM
How to use Onclick function for this jaya2109 BOOK: Beginning ASP 3.0 5 June 22nd, 2004 07:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.