DataGridView的常用用法 //讀取表Supplier並綁定到GridView中
private void BindGvSupplier()
OracleConnection conn = this
OracleCommand cmd = new OracleCommand(
OracleDataAdapter sda = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
sda
string[] SuppId = new string[ds
for (int i =
SuppId[i] = ds
}
this
this
this
this
this
this
}
//分頁觸發的事件
protected void gvSupplier_PageIndexChanging(object sender
this
this
this
this
}
//刪除按鈕觸發的事件
protected void gvSupplier_RowDeleting(object sender
int id = e
GridViewRow gvr = this
int SuppId=int
string sqlString =
//如果本頁只有一條數據
if (this
if (this
this
}
}
int result = ExecuteSql(sqlString);
if (result ==
this
}
this
this
}
//綁定刪除按鈕的確認提示
protected void gvSupplier_RowDataBound(object sender
if (e
LinkButton myLb = (LinkButton)(e
myLb
//鼠標經過時改變行的顏色
e
e
}
}
//執行一條Oracle語句
private int ExecuteSql(String sqlString)
//try
//{
OracleConnection conn = this
conn
OracleCommand cmd = new OracleCommand(sqlString
int effectedLine = cmd
conn
return effectedLine;
//}
//catch
//{
// return
//}
}
//點擊編輯按鈕時觸發的事件
protected void gvSupplier_RowEditing(object sender
string s = this
this
this
this
}
//點擊取消按鈕時觸發的事件
protected void gvSupplier_RowCancelingEdit(object sender
this
this
}
//點擊更新按鈕時觸發的事件
protected void gvSupplier_RowUpdating(object sender
int id = e
GridViewRow gvr = this
int suppId = int
string name = ((TextBox)gvr
string status = ((TextBox)gvr
string addr
string addr
string city = ((TextBox)gvr
string state = ((TextBox)gvr
string zip=((TextBox)gvr
string sqlString =
int result = ExecuteSql(sqlString);
if (result ==
//
}
this
this
}
//增加一條記錄
protected void btnAdd_Click(object sender
string name = this
string status = this
string addr
string addr
string city = this
string state = this
string zip = this
string sqlString =
if (this
this
}
else
this
}
this
}
//查看共有多少條數據
private int GetTotalCount()
//try
//{
OracleConnection conn = this
conn
OracleCommand cmd = new OracleCommand(
int count = Convert
conn
return count;
//}
//catch
//{
// return
//}
}
//彈出警告窗口
public void Alert(string str_Message
page
}
//彈出確認對話框
public void Confirm(string str_Message
page
}
protected void cbAllSelect_CheckedChanged(object sender
for(int i=
CheckBox cbSelect=(CheckBox)(gvSupplier
cbSelect
}
}
//當點擊刪除按鈕時刪除所有checkbox被選中的數據
protected void btnDel_Click(object sender
//如果用戶確認將觸發btnRealDel的事件
this
}
//真實的刪除操作
public void btnRealDel_Click(object sender
int count =
for (int i =
CheckBox myCb = (CheckBox)(this
if (myCb
count++;
HyperLink hl = (HyperLink)(this
int suppId = int
string sqlString =
this
}
}
if (count >
this
this
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11706.html