/**//// <summary>
/// onrowdatabound
/// </summary>
/// <param name="e"></param>
protected override void onrowdatabound(gridviewroweventargs e)
{
if (e.row.rowtype == datacontrolrowtype.header)
{
// gridviewrow的每个tablecell
for (int i = 0; i < e.row.cells.count; i++)
{
// tablecell里有一个control并且是linkbutton
if (e.row.cells[i].controls.count == 1 && e.row.cells[i].controls[0] is linkbutton)
{
// linkbutton的命令参数等于排序字段
if (((linkbutton)e.row.cells[i].controls[0]).commandargument == this.sortexpression)
{
image img = null;
label lbl = null; // 升序
if (this.sortdirection == sortdirection.ascending)
{
// 升序图片
if (!string.isnullorempty(_sorttip.sortascimage))
{
img = new image();
img.imageurl = base.resolveurl(_sorttip.sortascimage);
}
// 升序文字
if (!string.isnullorempty(_sorttip.sortasctext))
{
lbl = new label();
lbl.text = _sorttip.sortasctext;
}
}
// 降序
else if (this.sortdirection == sortdirection.descending)
{
// 降序图片
if (!string.isnullorempty(_sorttip.sortdescimage))
{
img = new image();
img.imageurl = base.resolveurl(_sorttip.sortdescimage);
}
// 降序文字
if (!string.isnullorempty(_sorttip.sortdesctext))
{
lbl = new label();
lbl.text = _sorttip.sortdesctext;
}
} // tablecell里加上图片
if (img != null)
{
e.row.cells[i].controls.add(img);
}
// tablecell里加上文字
if (lbl != null)
{
e.row.cells[i].controls.add(lbl);
}
}
}
}
} base.onrowdatabound(e);
}以上是采用的网上一段代码,
现在在gridview类中,重写LoadViewState方法,
请问如何获得类似的这个controls。
if (e.row.rowtype == datacontrolrowtype.header)e.row.cells[i].controls.add(img);排序字段名是可以知道的~~
// 类似于下面的代码
protected void grdPhoto_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((DropDownList)e.Row.FindControl("ddlType") != null)
{
DropDownList ddlType= (DropDownList)e.Row.FindControl("ddlType");
}
}
}
look
重写这个LoadViewState,在这个方法内,如何能找到类似的控制e.row.cells[i].controls.add(img); 而使得能够添加保存的图片img