怎么获得GridView某一行某一列的值
2个回答
展开全部
//点击GridView中的单元格,取到其单元格的行号 、列号、单元格内的值
protected void GridV_query_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
// i为列号,这良好总方法均
//e.Row.Cells[i].Text
// ((DataRowView)e.Row.DataItem).Row.ItemArray[i].ToString()
e.Row.Cells[i].Attributes.Add("onclick", "alert('行:" + e.Row.RowIndex + " 列:" + i + "单元格的值:" +((DataRowView)e.Row.DataItem).Row.ItemArray[i].ToString()+ "')");
}
}
}
protected void GridV_query_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
// i为列号,这良好总方法均
//e.Row.Cells[i].Text
// ((DataRowView)e.Row.DataItem).Row.ItemArray[i].ToString()
e.Row.Cells[i].Attributes.Add("onclick", "alert('行:" + e.Row.RowIndex + " 列:" + i + "单元格的值:" +((DataRowView)e.Row.DataItem).Row.ItemArray[i].ToString()+ "')");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询