Sonikag := fonte enesauribile di problematiche
ho scopiazzato un po' il tuo codice e ne ho fatto un esempietto che, manco a dirlo, funziona al primo colpo
pagina
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="a.aspx.vb" Inherits="prove_a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
<link href="../App_Themes/Tema1/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<h3>Aggiunta pulsante e gestore evento da codice</h3>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<hr />
<asp:Repeater ID="Repeater1" runat="server" EnableViewState="false">
<HeaderTemplate>
<table border="1">
<tr>
<td>ID</td>
<td>Nazione</td>
<td>Pulsante</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#NullToSpace(Eval("id"))%>
</td>
<td>
<%# NullToSpace(Eval("nazione")) %>
</td>
<td>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
codice in puro basic
codice:
Option Strict On
Partial Class prove_a
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
libreria.DataBind(Me.Repeater1, StringaConnessioneTest, "select * from citta")
End Sub
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.AlternatingItem, ListItemType.Item
Dim ph As PlaceHolder = DirectCast(e.Item.Controls(1), PlaceHolder)
Dim bt As New Button()
Dim dr As System.Data.Common.DbDataRecord = DirectCast(e.Item.DataItem, System.Data.Common.DbDataRecord)
bt.Text = dr("nazione").ToString()
bt.Width = Unit.Pixel(100)
bt.CommandArgument = dr("id").ToString & "_" & dr("nazione").ToString
AddHandler bt.Command, AddressOf bt_command
ph.Controls.Add(bt)
End Select
End Sub
Private Sub bt_command(ByVal sender As Object, ByVal e As CommandEventArgs)
Me.Label1.Text = e.CommandArgument.ToString
End Sub
End Class
ps. visto che mi funziona me lo conservo pure nella raccolta privata