Reputation: 57
I have a table which uses a repeater to display data. On each row there is a 'Delete' button which when clicked will retrieve the 'ClassId' from the row selected which will be used in a SQL DELETE query.
I don't know how to get the 'ClassId' from the row which was selected.
Snippet code from repeater:
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" ID="LblTitle"Text='<%# Eval("ClassId")%>' />
</td>
<td>
<asp:Label runat="server" ID="LblEmail" Text='<%# Eval("StartTime")%>' />
</td>
<td>
<asp:Label runat="server" ID="Label4" Text='<%# Eval("EndTime")%>' />
</td>
<td>
<asp:Label runat="server" ID="Label1" Text='<%# Eval("ClassDate")%>' />
</td>
<td>
<asp:Label runat="server" ID="Label2" Text='<%# Eval("BuildingName")%>' />
</td>
<td>
<asp:Label runat="server" ID="Label3" Text='<%# Eval("RoomCode")%>' />
</td>
<td>
<asp:Button ID="deleteBtn" runat="server" OnClick="deleteBtn_Click" class="btn btn-danger"
CommandArgument='<%# Eval("ClassId") %>'Text="Delete" />
</td>
</tr>
</ItemTemplate>
Code on .cs page:
protected void deleteBtn_Click(object sender, EventArgs e)
{
//SQL Delete query goes here using the ClassId to delete the row
}
Upvotes: 0
Views: 29
Reputation: 6586
You're passing the ClassId in the CommandArgument, get it from there.
protected void deleteBtn_Click(object sender, EventArgs e)
{
//SQL Delete query goes here using the ClassId to delete the row
var classid = ((Button)sender).CommandArgument;
}
Upvotes: 2