Help! Having trouble calling codebehind function from repeater results!

K

Kent P. Iler

Hi,

I have a data repeater that is returning a list of events. One of the
things I want to do is give the user a way to edit or delete an event. My
plan was to use an Imagebutton that would invoke a codebehind function that
would either edit or delete the item. My problem is I need to pass the
event_id as a parameter to each of these functions so I know what event to
edit/delete. The error code is complaining about the way I'm trying to pass
the parameter in the repeater results.

Can anyone help with this? I'm including the error code and source below.

Error Code:
----------------------------
http://localhost/BVA/edit_events.aspx(82) : error BC30201: Expression
expected.

AddHandler __ctrl.Click, AddressOf
Me.EditEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(82) : error BC30201: Expression
expected.

RemoveHandler __ctrl.Click, AddressOf
Me.EditEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(84) : error BC30201: Expression
expected.

AddHandler __ctrl.Click, AddressOf
Me.DeleteEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(84) : error BC30201: Expression
expected.

RemoveHandler __ctrl.Click, AddressOf
Me.DeleteEvent(<%#container.DataItem("event_id")%>)
----------------------------


Code sample:
----------------------------
<ItemTemplate>
<tr>
<td nowrap class="tableRow">
<%#container.DataItem("event_date")%></td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><%#container.DataItem("event_name")%></td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><asp:ImageButton Runat="server"
ImageUrl="Images/edit.gif"
onclick='EditEvent(<%#container.DataItem("event_id")%>)'></asp:ImageButton><
/td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><asp:ImageButton Runat="server"
ImageUrl="Images/delete.gif"
onclick='DeleteEvent( said:
</tr>
</ItemTemplate>
----------------------------


Thank you!

--Kent Iler
 
K

Kent P. Iler

OK. I figured it out. Just for future reference, here's the solution:

In the HTML code of the ASPX page, add an imagebutton with the CommandName
set to a text string, and the CommandArgumentset to the ID (or any other
value you need)

----------------------------
<ItemTemplate>
<tr>
<td nowrap class="tableRow"><%#container.DataItem("event_date")%>"</td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><%#container.DataItem("event_name")%></td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><asp:ImageButton Runat="server"
ImageUrl="Images/edit.gif" CommandName='EditEvent' CommandArgument=<%#
DataBinder.Eval(Container.DataItem, "event_id") %>
OnCommand="ImageButton_Command" ID="Imagebutton1"
NAME="Imagebutton1"></asp:ImageButton></td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap class="tableRow"><asp:ImageButton Runat="server"
ImageUrl="Images/delete.gif" CommandName='DeleteEvent' CommandArgument=<%#
DataBinder.Eval(Container.DataItem, "event_id") %>
OnCommand="ImageButton_Command" ID="Imagebutton2"
NAME="Imagebutton2"></asp:ImageButton></td>
</tr>
</ItemTemplate>
----------------------------


In the codebehind, add the ImageButton_Command routine where you can perform
logic based on the CommandName and CommandArgument.

----------------------------
Sub ImageButton_Command(ByVal sender As Object, ByVal e As
CommandEventArgs)
Dim tmpID As String
tmpID = e.CommandArgument
If (e.CommandName = "EditEvent") Then
'Edit here
EditEvent(tmpID)
ElseIf (e.CommandName = "DeleteEvent") Then
'Delete Here
DeleteEvent(tmpID)
End If
End Sub
---------------------------

--Kent


Kent P. Iler said:
Hi,

I have a data repeater that is returning a list of events. One of the
things I want to do is give the user a way to edit or delete an event. My
plan was to use an Imagebutton that would invoke a codebehind function that
would either edit or delete the item. My problem is I need to pass the
event_id as a parameter to each of these functions so I know what event to
edit/delete. The error code is complaining about the way I'm trying to pass
the parameter in the repeater results.

Can anyone help with this? I'm including the error code and source below.

Error Code:
----------------------------
http://localhost/BVA/edit_events.aspx(82) : error BC30201: Expression
expected.

AddHandler __ctrl.Click, AddressOf
Me.EditEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(82) : error BC30201: Expression
expected.

RemoveHandler __ctrl.Click, AddressOf
Me.EditEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(84) : error BC30201: Expression
expected.

AddHandler __ctrl.Click, AddressOf
Me.DeleteEvent(<%#container.DataItem("event_id")%>)
~
http://localhost/BVA/edit_events.aspx(84) : error BC30201: Expression
expected.

RemoveHandler __ctrl.Click, AddressOf
Me.DeleteEvent(<%#container.DataItem("event_id")%>)
----------------------------


Code sample:
----------------------------
<ItemTemplate>
<tr>
<td nowrap class="tableRow">
<%#container.DataItem("event_date")%></td>
<td nowrap class="tableRow">&nbsp;</td>
<td nowrap
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top