if (e.Row.RowType == DataControlRowType.DataRow)
{
# region 生成树形结构
string id = gvList.DataKeys[e.Row.RowIndex][
"
ID
"].ToString();
string pid = gvList.DataKeys[e.Row.RowIndex][
"
PID
"].ToString();
string level = gvList.DataKeys[e.Row.RowIndex][
"
Level
"].ToString();
//
增加节点的属性
e.Row.Attributes.Add(
"
id
", id);
e.Row.Attributes.Add(
"
pid
", pid);
e.Row.Attributes.Add(
"
level
", level);
e.Row.Attributes.Add(
"
expand
",
"
1
");
int indent = (
int.Parse(level) -
1) *
20;
//
判断是否有子节点
if (gvList.DataKeys[e.Row.RowIndex][
"
HasChild
"].ToString() ==
"
1
")
{
//
设置父节点前面的图片和点击事件
HtmlImage img =
new HtmlImage();
img.Src= TreeImagePath +
"
minimize.gif
";
img.Attributes.Add(
"
onclick
",
"
setExpand(this)
");
img.Style.Add(
"
cursor
",
"
pointer
");
e.Row.Cells[
0].Controls.Add(img);
e.Row.Cells[
0].Style[
"
font-weight
"] =
"
bold
";
}
else
{
indent +=
16;
}
e.Row.Cells[
0].Style[
"
padding-left
"] = indent +
"
px
";
e.Row.Cells[
0].Controls.Add(
new LiteralControl(e.Row.Cells[
0].Text));
# endregion
e.Row.Attributes[
"
onmouseover
"] =
"
style.backgroundColor='#F2FDDB'
";
e.Row.Attributes[
"
onmouseout
"] =
"
style.backgroundColor=''
";
}