Hallo,
hier erstmal der Code :
C#
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
//using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Data;
public partial class MainSite : System.Web.UI.Page
{
ConnectionStringSettings connectionInfo;
DataTable datTable;
List<ProduktAktion> aktList;
Image noPicture;
protected class ProduktAktion
{
Image picture { get; set; }
String description { get; set; }
String mixes { get; set; }
String unit { get; set; }
String price_original { get; set; }
String price_aktion { get; set; }
protected internal ProduktAktion(Image new_pic, String new_desc, String new_mixes, String new_unit, String new_price_or, String new_price_akt)
{
picture = new_pic; description = new_desc; mixes = new_mixes; unit = new_unit; price_original = new_price_or; price_aktion = new_price_akt;
}
}
protected void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
GridViewAktion.DataBind();
}
protected void GridView_Load(object sender, EventArgs e)
{
noPicture = Image.FromFile(@"C:\Users\Thomas\Documents\Visual Studio 2010\WebSites\SchTeddUndMehr\noImage.bmp");
aktList = new List<ProduktAktion>();
connectionInfo = ConfigurationManager.ConnectionStrings['RefToDatabase'];
SqlConnection connection = new SqlConnection(connectionInfo.ConnectionString);
SqlCommand selectCommand = new SqlCommand("select Bild, Beschreibung, Menge, Einheit, Preis_netto, Rabatt, MWST, Aktion, Aktiv from Produkte", connection);
selectCommand.Connection.Open();
SqlDataReader dataReader = selectCommand.ExecuteReader();
double dnormalPrice;
decimal normalPrice, aktionPrice;
Image aPic = null;
datTable = new DataTable();
datTable.Columns.Add("Bild");
datTable.Columns.Add("Beschreibung");
datTable.Columns.Add("Menge");
datTable.Columns.Add("Einheit");
datTable.Columns.Add("Preis normal");
datTable.Columns.Add("Preis jetzt");
while (dataReader.Read())
{
if ((bool)dataReader['Aktion'] && (bool)dataReader['Aktiv'])
{
dnormalPrice = (double)dataReader['Preis_netto'] * ((((double)(int)dataReader['MWST']) / 100) + 1);
normalPrice = (decimal)dnormalPrice;
aktionPrice = (decimal)(dnormalPrice - (dnormalPrice * (double)dataReader['Rabatt'] / 100));
if (System.DBNull.Value != dataReader['Bild'])
{
Byte[] bytePic = new Byte[0];
bytePic = (Byte[])dataReader['Bild'];
MemoryStream streamPic = new MemoryStream(bytePic);
aPic = Image.FromStream(streamPic);
}
else
aPic = noPicture;
DataRow newRow = datTable.NewRow();
newRow['Bild'] = aPic;
newRow['Beschreibung'] = dataReader['Beschreibung'].ToString();
newRow['Menge'] = String.Format("{0:f}", (double)dataReader['Menge']);
newRow['Einheit'] = dataReader['Einheit'].ToString();
newRow['Preis normal'] = normalPrice.ToString("C2", new System.Globalization.CultureInfo("de-DE"));
newRow['Preis jetzt'] = aktionPrice.ToString("C2", new System.Globalization.CultureInfo("de-DE"));
datTable.Rows.Add(newRow);
//aktList.Add(new ProduktAktion(noPicture, dataReader['Beschreibung'].ToString(), String.Format("{0:f}", (double)dataReader['Menge']), dataReader['Einheit'].ToString(), normalPrice.ToString("C2", new System.Globalization.CultureInfo("de-DE")), aktionPrice.ToString("C2", new System.Globalization.CultureInfo("de-DE"))));
}
}
dataReader.Close();
connection.Close();
GridViewAktion.DataSource = datTable;
GridViewAktion.DataBind();
}
protected void ButtAktion_Click(object sender, EventArgs e)
{
}
}
Alles anzeigen
und zwar schaff ich es einfach nicht, daß die Daten im GridView angezeigt werden !
Daten werden alle geladen, GridView wird angezeigt aber nicht die Daten im GridView !
Kann mir da bitte irgend jemand helfen ?