Skicka med en parameter
Går det att skickamed en parameter när jag klickar på tex LinkButton1 som jag kan snappa upp i min sub "LinkButton_Click" ?
<code>
<%@ Page Language="VB" %>
<script runat="server">
Sub LinkButton_Click(sender As Object, e As EventArgs)
label1.text = now
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:LinkButton id="LinkButton1" onclick="LinkButton_Click" runat="server">LinkButton</asp:LinkButton>
<br/>
<asp:LinkButton id="LinkButton2" onclick="LinkButton_Click" runat="server">LinkButton</asp:LinkButton>
<br/>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</form>
</body>
</html>
</code>Sv: Skicka med en parameter
Detta fick jag att funka..... nu är bara frågan kvar hur man listar upp lite "linkbutton"s dynamiskt?
<code>
<%@ Page Language="VB" %>
<script runat="server">
Sub LinkButton_Command(sender As Object, e As CommandEventArgs)
label1.text = e.CommandName + " " + e.CommandArgument
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:LinkButton id="LinkButton1" runat="server" CommandArgument="1000" CommandName="Pnr" OnCommand="LinkButton_Command">LinkButton</asp:LinkButton>
<br />
<asp:LinkButton id="LinkButton2" runat="server" CommandArgument="2000" CommandName="Pnr" OnCommand="LinkButton_Command">LinkButton</asp:LinkButton>
<br />
<asp:Label id="Label1" runat="server">Label</asp:Label>
</form>
</body>
</html>
</code>Sv:Skicka med en parameter
Hittade lite kod som ladda upp en linkbutton:s dynamiskt.... men nu vill jag inte ha de i en "table" utan kunna pytsa ut en i taget i egen skapad tabell. Går det att lösa ?
<code>
<%@ Page Language="VB" %>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Put user code to initialize the page here
For a As Integer = 1 To 3
Dim tr As New TableRow
Dim td1 As New TableCell
Dim lb As New LinkButton
lb.Text = "knapp " & CStr(a)
lb.CommandArgument = CStr(a)
AddHandler lb.Command, AddressOf menu_command
td1.Controls.Add(lb)
tr.Controls.Add(td1)
Table1.Controls.Add(tr)
Next
End Sub
Private Sub menu_command(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
' hämtar id för tryckt knapp
Dim item_number As String = e.CommandArgument()
Response.Write("Du tryckte: " & item_number)
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Table id="Table1" runat="server"></asp:Table>
</form>
</body>
</html>
</code>