Buttons on a DataList

N_K

Member
Joined
Oct 10, 2006
Messages
22
Programming Experience
3-5
Hi,

On each row of a DataList I have a button which will allow the user to edit that row's details and bring up an extra bit of the page.

I cant seem to refer to the button in my codebehind file, VS insists the button has not been declared.

How can I sort this out?

cheers,

NK
 
Hi,

I dunno if this is correct coz I am thinking it off-hand

VB.NET:
Dim btn As Button = CType(e.Item.Cells(yourcolumnIndex).FindControl("theButtonID"), button)

I used to have a problem similar to yours. VS could not recognise my HtmlInputControl, so this is what I did.

VB.NET:
Dim ht As HtmlInputControl = CType(e.Item.Cells(yourcolumnIndex).FindControl("ImageEdit"), HtmlInputControl)
 
i can access buttons in a similar way but I just cant seem to be able to create a subroutine for the click event of the button.

So far at the start of my code behind I have tried this:

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] DLEditButton [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Web.UI.WebControls.Button
[/SIZE]

and then later on as part of the ItemDataBound Subroutine of my Datalist I have:

VB.NET:
[SIZE=2]
DLEditButton = e.Item.FindControl([/SIZE][SIZE=2][COLOR=#800000]"EditLink"[/COLOR][/SIZE][SIZE=2])
[/SIZE]

in an attempt to access the button in each row of the dataset.

Later on I then have how I understand I should do the Click event

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DLEditButton_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] DLEditButton.Click
GenerateContactDetail([/SIZE][SIZE=2][COLOR=#800000]"Edit"[/COLOR][/SIZE][SIZE=2], LblAddressBookId.Text)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

My compiler doesnt like that and keeps giving me this message

"BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types."

What can I do? there must be some way of assigning buttons on each row of a datalist and handling their Click event.?!

I appreciate your help.

NK
 
The DataList.ItemCommand event happens for item buttons clicked. You can give each button different CommandName property and separate these in event parameter e.CommandName.
 

Latest posts

Back
Top