using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.OleDb; using System.Data.SqlClient; using System.Data; namespace GridVewe_sample { public partial class WebForm1 : System.Web.UI.Page { String ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Database1.accdb"; // MDB–¼‚È‚Ç static bool newflg; OleDbConnection conn; OleDbCommand comm; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { conn = new OleDbConnection(); conn.ConnectionString = ConnectionString; conn.Open(); DataTable dt = new DataTable(); OleDbDataAdapter adapter = new OleDbDataAdapter(); comm = new OleDbCommand(); var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT id,DA FROM DAYDATA"; adapter.SelectCommand = cmd; adapter.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); conn.Close(); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int args = Int32.Parse((String)e.CommandArgument); switch (e.CommandName) { case "SELECT1": Response.Write("SELECT1 "); String isbn = (String)GridView1.DataKeys[args].Value.ToString(); Response.Write(isbn); break; case "SELECT2": Response.Write("SELECT2 "); String isbn2 = (String)GridView1.DataKeys[args].Value.ToString(); Response.Write(isbn2); String ass = (string)GridView1.DataKeys[args]["DA"].ToString(); Response.Write(" "+ass); break; } } } }