Hey, I have following problem:
I have a list of Inovices which each have an id, which I want to set as commandargument on a button, but I get an empty string, I have tried to google and have found I should use <%# eval(inovice.id.ToString()) %>, My page and code behinde looks like this:
Page:
Code behind
Can anyone help - thanks in advance
I have a list of Inovices which each have an id, which I want to set as commandargument on a button, but I get an empty string, I have tried to google and have found I should use <%# eval(inovice.id.ToString()) %>, My page and code behinde looks like this:
Page:
<%@ Page Title="Contact" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Inovices.aspx.cs" Inherits="SpeciallseringsWebpage.Inovices" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<table border="1">
<thead>
<tr>
<th>Inovice number</th>
<th>Date</th>
<th>VIEW</th>
</tr>
</thead>
<%SpecialliseringLibary.Customer customer = (SpecialliseringLibary.Customer) Session["customer"]; %>
<%if(customer != null){
int i = 1;
%>
<%foreach(SpecialliseringLibary.Inovice inovice in SpecialliseringLibary.Service.getInoviceByCustomerId(customer.id)){ %>
<%
if (i % 2 == 0) {
%>
<tr>
<%
}else{
%>
<tr "background: #C0C0C0;" >
<%} %>
<td>
<%= inovice.id.ToString() %>
</td>
<td><%= inovice.Date.ToString() %>
</td> <%--"3034201A-69EA-4A03-BB5E-90620C899EEB"--%>
<td>
<%string id = inovice.id.ToString();
Response.Write(id); %>
<asp:Button runat="server" Text="=>" onclick="btnViewInovice" CommandArgument=<%# inovice.ToString() %> /> <%--inovice.id.ToSTring())--%>
</td>
</tr>
<%
i++;
} %>
<%} %>
</table>
</asp:Content>
Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SpeciallseringsWebpage
{
public partial class Inovices : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["customer"] == null) {
Server.Transfer("Default.aspx");
}
}
public void btnViewInovice(object sender, EventArgs e) {
Button btn = (Button)sender;
string id = btn.CommandArgument;
Session["chosenInovice"] = id;
Server.Transfer("overview.aspx");
}
}
}
Can anyone help - thanks in advance