using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
public partial class member_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
public void bindGridView()
{
// string variable to store the connection string
// defined in ConnectionStrings section of web.config file.
string connStr = ConfigurationManager.ConnectionStrings["MsqlDB"].ConnectionString;
// object created for SqlConnection Class.
MySqlConnection mySQLconnection = new MySqlConnection(connStr);
// if condition that can be used to check the sql connection
// whether it is already open or not.
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
}
MySqlCommand mySqlCommand = new MySqlCommand("select * from amphur", mySQLconnection);
MySqlDataAdapter mySqlAdapter = new MySqlDataAdapter(mySqlCommand);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
GridView1.DataSource = myDataSet;
GridView1.DataBind();
//if condition that can be used to check the sql connection
//if it is open then close it.
if (mySQLconnection.State == ConnectionState.Open)
{
mySQLconnection.Close();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
protected void GridView1_RowDataBound(object sender, GridViewPageEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = "แก้ไข";
}
}
}