I am trying to use a Repeater inside a Updatepanel and have Buttons that delete one entery in the Database and get the new Data for the Repeater and Update the Panel. I have tried a LinkButton, but it does always postback and the page relodes. Then i tried a regular Button and create a Event for that Button on DataBound Event. But it doesnt work. Here is the code:
aspx file:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="Panel">
<ContentTemplate>
<table cellpadding="0" cellspacing="0" id="saveTable">
<tr style="font-weight: bold;">
<td>Erstellt am</td>
<td>Anforderer</td>
<td>Werk</td>
<td>Gebäude</td>
<td>Start Datum</td>
<td>Löschen</td>
<td>Benutzen</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr id="Meldung<%# DataBinder.Eval(Container.DataItem,"meldungId")%>">
<td><%# DataBinder.Eval(Container.DataItem, "timestamp").ToString().Substring(0, 10)%></td>
<td><%# DataBinder.Eval(Container.DataItem,"nameAnforderer") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Werk") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Building") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"startDatum").ToString().Substring(0, 10) %></td>
<td>
<asp:Button runat="server" ID="test"/>
</td>
<td></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>
and in the code behind i give the Button with id = test a event
protected void deleteMeldung(object sender, EventArgs e) {
System.Threading.Thread.Sleep(5000);
}
protected void Repeater1_ItemDataBound(object source, RepeaterItemEventArgs e) {
RepeaterItem repeaterSource = e.Item;
Button btn1 = repeaterSource.FindControl("test") as Button;
DataRowView drv = e.Item.DataItem as DataRowView;
string meldungId = drv.Row["meldungId"].ToString();
btn1.ID = "myNewButton"+meldungId;
btn1.Click += new EventHandler(deleteMeldung);
btn1.Text = "delete";
}
so whats working is passing the Text and the ID to each button like that. But the Buttons do not have the Click Event to call deleteMeldung()