最近在使用 CSS Control Adapter Toolkit Update 时发现
GridView中的Column Visible=false时仍然有显示 DetailsView仍然有该问题存在修改代码如下:
修改GridViewAdapter的WriteRows方法
private void WriteRows(HtmlTextWriter writer, GridView gridView, GridViewRowCollection rows, string tableSection) |
{ |
if (rows.Count > 0) |
{ |
writer.WriteLine(); |
writer.WriteBeginTag(tableSection); |
writer.Write(HtmlTextWriter.TagRightChar); |
writer.Indent++; |
foreach (GridViewRow row in rows) |
{ |
writer.WriteLine(); |
writer.WriteBeginTag("tr"); |
string className = GetRowClass(gridView, row); |
if (className.Length > 0) |
{ |
writer.WriteAttribute("class", className); |
} |
writer.Write(HtmlTextWriter.TagRightChar); |
writer.Indent++; |
//---------- Bolik Fixed for not Visible Columns |
//foreach (TableCell cell in row.Cells) |
//{ |
// writer.WriteLine(); |
// cell.RenderControl(writer); |
//} |
for (int i = 0; i < row.Cells.Count; i++) |
{ |
if (gridView.Columns[i].Visible) |
{ |
writer.WriteLine(); |
row.Cells[i].RenderControl(writer); |
} |
} |
//---------- Bolik Fixed for not Visible Columns |
writer.Indent--; |
writer.WriteLine(); |
writer.WriteEndTag("tr"); |
} |
writer.Indent--; |
writer.WriteLine(); |
writer.WriteEndTag(tableSection); |
} |
} |
修改DetailsViewAdapter的BuildItem方法
protected override void BuildItem(HtmlTextWriter writer) |
{ |
if (IsDetailsView && (ControlAsDetailsView.Rows.Count > 0)) |
{ |
writer.WriteLine(); |
writer.WriteBeginTag("div"); |
writer.WriteAttribute("class", _classData); |
writer.Write(HtmlTextWriter.TagRightChar); |
writer.Indent++; |
writer.WriteLine(); |
writer.WriteBeginTag("ul"); |
writer.Write(HtmlTextWriter.TagRightChar); |
writer.Indent++; |
//---------- Bolik Fixed for not Visible Columns |
for (int i = 0; i < ControlAsDetailsView.Rows.Count; i++) |
//foreach (DetailsViewRow row in ControlAsDetailsView.Rows) |
{ |
DetailsViewRow row = ControlAsDetailsView.Rows[i]; |
if ((!ControlAsDetailsView.AutoGenerateRows) && |
((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert) && |
(!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible)) |
{ |
continue; |
} |
if (ControlAsDetailsView.Fields[i].Visible) |
{ |
writer.WriteLine(); |
writer.WriteBeginTag("li"); |
if ((row.RowState & DataControlRowState.Alternate) == DataControlRowState.Alternate) |
{ |
writer.WriteAttribute("class", "AspNet-DetailsView-Alternate"); |
} |
writer.Write(HtmlTextWriter.TagRightChar); |
writer.Indent++; |
writer.WriteLine(); |
for (int iCell = 0; iCell < row.Cells.Count; iCell++) |
{ |
TableCell cell = row.Cells[iCell]; |
writer.WriteBeginTag("span"); |
if (iCell == 0) |
{ |
writer.WriteAttribute("class", "AspNet-DetailsView-Name"); |
} |
else if (iCell == 1) |
{ |
writer.WriteAttribute("class", "AspNet-DetailsView-Value"); |
} |
else |
{ |
writer.WriteAttribute("class", "AspNet-DetailsView-Misc"); |
} |
writer.Write(HtmlTextWriter.TagRightChar); |
if (cell.Text != null) |
{ |
writer.Write(cell.Text); |
} |
foreach (Control cellChildControl in cell.Controls) |
{ |
cellChildControl.RenderControl(writer); |
} |
writer.WriteEndTag("span"); |
} |
writer.Indent--; |
writer.WriteLine(); |
writer.WriteEndTag("li"); |
} |
//---------- Bolik Fixed for not Visible Columns |
} |
writer.Indent--; |
writer.WriteLine(); |
writer.WriteEndTag("ul"); |
writer.Indent--; |
writer.WriteLine(); |
writer.WriteEndTag("div"); |
} |
} |