GridView 中RowDataBound 获取绑定后的各个字段的值
protected void GridView_dept_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex % 2 == 0)
{
e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#F5F5F5");
}
else
{
e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#D9D9D9");
}
DataRowView myrows = (DataRowView)e.Row.DataItem;
DataRow dr = myrows.Row;
Response.Write(dr["dept_id"]);
string CaseOrderInfo = "";
CaseOrderInfo += dr["dept_id"].ToString().Trim();
CaseOrderInfo += "^" + dr["dept_name"].ToString().Trim();
CaseOrderInfo += "^" + dr["dept_orderno"].ToString().Trim();
//Response.Write (CaseOrderInfo);//测试
在RowDataBound事件中..
if (e.Row.RowType == DataControlRowType.DataRow) //判断是否数据行;
{
DataRowView drv = (DataRowView)e.Row.DataItem;
string haveimg = drv["Hd_HaveImage"].ToString();
string uid = drv["Hd_Id"].ToString();
}
可以直接读取数据库中未绑定到列的字段. 或者可以用
if (e.Row.RowType == DataControlRowType.DataRow) //判断是否数据行;
{
string haveimg = DataBinder.eval_r(e.Row.DataItem , "Hd_HaveImage").ToString();
}