Reputation: 7759
I want when the user clicks on the Panel
that's having class session_box
a click event fire. But when i click on it, nothing happen. When i debugged the code, the ItemCommand
event doesn't even get called !
Here's my code :
HTML:
<div id="sessions_wrapper">
<asp:Repeater ID="sessions_repeater" runat="server"
DataSourceID="SqlDataSource1"
onitemcommand="sessions_repeater_ItemCommand">
<ItemTemplate>
<asp:Panel CssClass="session_box" runat="server" data-session-id='<%# Eval("session_id") %>'>
<asp:Image CssClass="session_icon" runat="server" ImageUrl='<%# Eval("session_cover") %>' alt="" />
<div class="session_info">
<p>Title: <%# Eval("session_name") %></p>
<p>Date: <%# Eval("session_date") %></p>
<p>Photos: <%# Eval("session_photos") %></p>
</div>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBCS %>"
ProviderName="<%$ ConnectionStrings:DBCS.ProviderName %>"
SelectCommand="SELECT * FROM [sessions]"></asp:SqlDataSource>
</div>
C# :
protected void sessions_repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string sid = ((Panel)e.CommandSource).Attributes["data-session-id"];
Response.Redirect("sessions.aspx?sid=" + sid);
}
Upvotes: 0
Views: 2379
Reputation: 6249
This is because a Panel does not raise a Command event. Controls such as Button, ImageButton, LinkButton, etc raise this event.
You may need to rethink your UI layout to include some type of button to raise the Command event.
Upvotes: 1
Reputation: 3088
Big Edit: I think an easier way would be to add an ImageButton instead of your Image control. That has two properties, CommandName and CommandArgument. You can use those to pass parameters to the code behind without any casting.
Upvotes: 1