更新时间:2023-12-06 10:28:46
foreach (GridViewRow row in grid.Rows)
{
foreach (TableCell cell in row.Cells)
{
string cellValue = cell.Text.ToString();
}
}
如果有帮助,请 投票 和 接受答案 .
Please vote and Accept Answer if it Helped.
int PID = 0;
private void dgrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dgrid.Rows.Count >= 0)
{
if (e.RowIndex >= 0)
{
PID = Convert.ToInt32(dgrid.Rows[e.RowIndex].Cells["PID"].Value.ToString());
}
}
}
这样,您可以获取单元格值..
如果您要将单元格值更新为数据库
使用CellValueChanged事件.
this way u can fetch the cell values..
if u want to update cell value to Database
use CellValueChanged Event..