ups, siden er sådan her
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MoensVandrehjem
{
/// <summary>
/// Summary description for Opdate.
/// </summary>
public class Update : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ChooseFile;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid grid;
private static ArrayList arlofinfo = new ArrayList();
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.Button Button2;
private Database db = Database.Instance();
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
FillDropDown();
}
private void BindGrid()
{
grid.DataSource = GetData();
grid.DataBind();
}
private ArrayList GetData()
{
return arlofinfo;
}
public void FillDropDown()
{
db.OpenConnection();
IDataReader reader = db.SelectSQL("SELECT * FROM TOC");
if(reader != null)
{
while(reader.Read())
{
ChooseFile.Items.Add(reader["TableName"].ToString());
}
reader.Close();
}
db.CloseConnection();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.grid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_CancelCommand);
this.grid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_EditCommand);
this.grid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_UpdateCommand);
this.grid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_DeleteCommand);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void grid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
grid.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}
private void grid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string item = ((Label)e.Item.Cells[2].Controls[1]).Text;
string dan = ((TextBox)e.Item.Cells[3].Controls[1]).Text;
string eng = ((TextBox)e.Item.Cells[4].Controls[1]).Text;
string tys = ((TextBox)e.Item.Cells[5].Controls[1]).Text;
string danheader = ((TextBox)e.Item.Cells[6].Controls[1]).Text;
string engheader = ((TextBox)e.Item.Cells[7].Controls[1]).Text;
string tysheader = ((TextBox)e.Item.Cells[8].Controls[1]).Text;
foreach (HoldInf h in arlofinfo)
{
if(h.ID == item)
{
db.CallDatabase("UPDATE " + this.ChooseFile.SelectedItem.Text + " SET DAN = '" + dan + "', ENG = '" + eng + "', TYSK ='" + tys + "', HeaderDK = '" + danheader + "', HeaderENG = '" + engheader + "', HeaderTYSK = '" + tysheader + "' WHERE id = " + item +";", true);
h.Dansk = dan;
h.Engelsk = eng;
h.Tysk = tys;
h.DanHeader = danheader;
h.EngHeader = engheader;
h.TysHeader = tysheader;
break;
}
}
grid.EditItemIndex = -1;
BindGrid();
}
private void grid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
grid.EditItemIndex = -1;
BindGrid();
}
private void grid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int rowToDelete = e.Item.ItemIndex;
string s = ((Label)e.Item.Cells[2].Controls[1]).Text.Trim();
HoldInf h2 = null;
foreach (HoldInf h in arlofinfo)
{
if(h.ID == s)
{
h2 = h;
db.CallDatabase("DELETE FROM " + this.ChooseFile.SelectedItem.Text + " WHERE id = " + s, true);
break;
}
}
arlofinfo.Remove(h2);
BindGrid();
}
private void Button2_Click(object sender, System.EventArgs e)
{
db.OpenConnection();
IDataReader read = db.SelectSQL("SELECT * FROM " + this.ChooseFile.SelectedItem.Text.Trim());
if(read != null)
{
while (read.Read())
{
HoldInf ho = new HoldInf(Convert.ToInt32(read[0]), read[4].ToString(), read[5].ToString(), read[6].ToString(), read[1].ToString(), read[2].ToString(), read[3].ToString());
arlofinfo.Add(ho);
}
}
db.CloseConnection();
BindGrid();
}
}
public class HoldInf
{
private int _id = 0;
private string _dansk = "";
private string _engelsk = "";
private string _tysk = "";
private string _danhead = "";
private string _enghead="";
private string _tyshead = "";
public HoldInf(int id, string dansk, string engelsk, string tysk, string danhead, string enghead, string tyshead)
{
_id = id;
_dansk = dansk;
_engelsk = engelsk;
_tysk = tysk;
_danhead = danhead;
_enghead = enghead;
_tyshead = tyshead;
}
public string ID
{
get{return _id.ToString();}
}
public string Dansk
{
set{_dansk = value;}
get{return _dansk;}
}
public string Engelsk
{
set{_engelsk = value;}
get{return _engelsk;}
}
public string Tysk
{
set{_tysk = value;}
get{return _tysk;}
}
public string DanHeader
{
set{_danhead = value;}
get{return _danhead;}
}
public string EngHeader
{
set{_enghead = value;}
get{return _enghead;}
}
public string TysHeader
{
set{_tyshead = value;}
get{return _tyshead;}
}
}
}
ASPX - filen ---------------------------------------------------------------
<%@ Page language="c#" Codebehind="Update.aspx.cs" AutoEventWireup="false" Inherits="MoensVandrehjem.Update" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Opdate</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="
http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:dropdownlist id="ChooseFile" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 16px"
runat="server" Width="136px"></asp:dropdownlist>
<HR style="Z-INDEX: 102; LEFT: 24px; WIDTH: 79.27%; POSITION: absolute; TOP: 48px; HEIGHT: 1px"
width="79.27%" SIZE="1">
<asp:Table id="Table1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 64px" runat="server"></asp:Table>
<asp:DataGrid id="grid" style="Z-INDEX: 104; LEFT: 24px; POSITION: absolute; TOP: 96px" runat="server"
Width="968px" AutoGenerateColumns="False">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderTemplate>
ID
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=idof Runat= server Text='<% #DataBinder.Eval(Container, "DataItem.ID") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Dansk
</HeaderTemplate>
<ItemTemplate>
<asp:Label id=dansk Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Dansk") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox5" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Dansk") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Engelsk
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="engelsk" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Engelsk") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox4" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Engelsk") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Tysk
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="tysk" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Tysk") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox3" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.Tysk") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Dansk Title
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="danskheader" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.DanHeader") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox2" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.DanHeader") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Engelsk Title
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="engelskheader" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.EngHeader") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Textbox1" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.EngHeader") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
Tysk title
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="tyskheader" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.TysHeader") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="Label1" Runat=server Text='<% #DataBinder.Eval(Container, "DataItem.TysHeader") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:Button id="Button2" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 16px" runat="server"
Text="Vælg side"></asp:Button></form>
</body>
</HTML>