Groups | Blog | Home
all groups > asp.net datagrid control > march 2008 >

asp.net datagrid control : How can i update data GridView content?



sharonfongfong@gmail.com
3/18/2008 9:53:47 PM
HI, my data gridview have been connected to Web services(i use MySQL
database) and i had write a update method, i would like to use C#
code, when i click the checkbox and click the delete button, the
coloumn - "Status" , the "Status" content will be change from "In
Process" to "Cancel" , can anyone help me?


Here is my GridView
http://i5.photobucket.com/albums/y172/sharonfong/gridw.jpg

Here is update web method
[WebMethod]
public int UpdateReserve(string reserveNo)
{

String sql12 = String.Format("UPDATE reservation set rStatus =
'Cancel' where reserveNo ='" + reserveNo + "'");

return executeNonQuery(sql12);

}


Here is my DataSet web method

[WebMethod(Description = "Get all reserve from reservation table")]

public DataSet GetUserReservation(string uid)

{


string sql = "SELECT reserveNo, bName, ISBN, rDate,
warningDate, bStatus FROM reservation where uid = '" + uid + "'";

OdbcConnection conn = new OdbcConnection(Path());
OdbcCommand cmd = new OdbcCommand(sql, conn);

conn.Open();

OdbcDataReader myReader = cmd.ExecuteReader();



DataTable myTable = new DataTable("myTable");
myTable.Columns.Add("Reserve No.", typeof(string));

myTable.Columns.Add("Book Title", typeof(string));

myTable.Columns.Add("ISBN", typeof(string));

myTable.Columns.Add("Reserve Date",
typeof(string));

myTable.Columns.Add("Warning Date", typeof(string));

myTable.Columns.Add("Status", typeof(string));


while (myReader.Read())

{
myTable.Rows.Add(new object[]

{

myReader["reserveNo"].ToString(),
myReader["bName"].ToString(), myReader["ISBN"].ToString(),
myReader["rDate"].ToString(),
myReader["warningDate"], myReader["bStatus"]});

}

//myTable.Load(reader);

myTable.AcceptChanges();

DataSet ds = new DataSet();

ds.Tables.Add(myTable);

ds.AcceptChanges();

return ds;


sharonfongfong@gmail.com
3/18/2008 9:59:47 PM
Here is my button click code, but it is not work

protected void ImageButton1_Click(object sender,
ImageClickEventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox chk =
this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
if (chk.Checked == true)
{
string id =
this.GridView1.DataKeys[i].Value.ToString();
//do delete here
webLibrary.Service wLibrary = new
webLibrary.Service();
GridView1.DataSource = wLibrary.DeleteReserve(id);
GridView1.DataBind();
}

AddThis Social Bookmark Button