【发布时间】:2014-11-10 22:48:37
【问题描述】:
我有一个网格视图。
我正在根据行命令事件中的逻辑将网格视图中某些行的颜色更改为红色。
现在我想对网格视图进行排序,使彩色行出现在网格视图的顶部。 有什么办法我可以做到这一点。 ?我的代码如下:
aspx:
<asp:GridView ID="gvMain" runat="server" ShowFooter="true"OnRowCommand="gvMain_RowCommand">
<Columns>
<HeaderStyle Width="15%"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Std" SortExpression="Std" >
<ItemTemplate>
<asp:Label ID="lblStd" runat="server" Text='<%#Eval("Std") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList Width="200" runat="server" id="cboStd" Font-Size="7pt" Height="12pt">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept" SortExpression="Dept" >
<ItemTemplate>
<asp:Label ID="lblDept" runat="server" Text='<%#Eval("Dept") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList Width="100" runat="server" id="cboDept" Font-Size="7pt" Height="12pt">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
aspx.cs
protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
List<StdMap> lstStd = null;
if (gvMain.EditIndex == e.Row.RowIndex)
{
lstStd = Service.GetDetails();
if (e.Row.RowType == DataControlRowType.DataRow)
{
lstStd = Service.GetDetails();
ReportMap row = ((ReportMap)e.Row.DataItem);
if ("condition to change color to red ")
{
e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
}
else
{
}
row = null;
}
}
catch (Exception ex)
{
}
}
我应该怎么做才能让所有前色为红色的行出现在网格视图的顶部?
【问题讨论】:
-
那么实际的
if ("condition to change color to red ")是什么样的......? -
您的数据源是什么样的?你能在其中的每一行中添加一个标志吗?
-
我会使用 SQL 对其进行排序,然后将其呈现在您的网格中。
-
我不明白为什么我被否决了。我的数据源是一个强类型列表。
-
如果条件复杂,我在问题中简化了我的网格视图,以便于理解。在实际情况下,我还有一个百分比列,如果特定类型的总百分比大于 1000。我用红色突出显示所有这些列