- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 gridview,我在使用 RowDataBound 后更改了一些行的颜色....
这是我的 GridView
<asp:GridView ID="grdvEventosVendedor" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DatakeyNames="idCita"
EmptyDataText="No Hay Eventos Para Este Vendedor" ForeColor="#333333"
GridLines="None" AllowSorting="True"
onpageindexchanging="grdvEventosVendedor_PageIndexChanging"
onrowcommand="grdvEventosVendedor_RowCommand"
onsorting="grdvEventosVendedor_Sorting" CellSpacing="1"
onrowdatabound="grdvEventosVendedor_RowDataBound" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775"/>
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnEdicEvento" runat="server"
CommandArgument='<%# Eval("idCita")%>' CommandName="Edicion"
Height="32px" ImageUrl="~/img/pencil_32.png" Width="32px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnDelete" runat="server"
CommandName="Borrar"
ImageUrl="~/img/1385_Disable_16x16_72.png"
onclientclick="return confirm('¿Desea eliminar el registro?');"
CommandArgument='<%# Eval("idCita")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cliente" HeaderText="Cliente" InsertVisible="False" ReadOnly="True" SortExpression="Cliente" ItemStyle-Width="50px" />
<asp:BoundField DataField="Empresa" HeaderText="Empresa" InsertVisible="False" ReadOnly="True" SortExpression="Empresa" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Telefono" HeaderText="Telefono" InsertVisible="False" ReadOnly="True" SortExpression="Telefono" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Nextel" HeaderText="Nextel" InsertVisible="False" ReadOnly="True" SortExpression="Nextel" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Tipo" HeaderText="Tipo" InsertVisible="False" ReadOnly="True" SortExpression="Tipo" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Descripcion" HeaderText="Descripcion" InsertVisible="False" ReadOnly="True" SortExpression="Descripcion" ItemStyle-Width="150px"/>
<asp:TemplateField HeaderText="Fecha" SortExpression="Fecha" ItemStyle-Width="50px">
<ItemTemplate>
<asp:Label ID="lblFecha" runat="server" Text='<%#Bind("Fecha", "{0:dd/MM/yyyy}")%>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbxFecha" runat="server" Text='<%#Bind("Fecha","{0:dd/MM/yyyy}") %>' ValidationGroup="gpEdicionAgenda">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="HoraInicio" HeaderText="Hora" InsertVisible="False" ReadOnly="True" SortExpression="HoraInicio" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Lugar" HeaderText="Lugar" InsertVisible="False" ReadOnly="True" SortExpression="Lugar" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Estado" HeaderText="Estado" InsertVisible="False" ReadOnly="True" SortExpression="Estado" ItemStyle-Width="50px"/>
<%--<asp:TemplateField HeaderText="Estado" ItemStyle-Width="50px">
<ItemTemplate>
<asp:DropDownList ID="dpdListEstado" runat="server" OnSelectedIndexChanged="dpdListEstado_SelectedIndexChanged" AutoPostBack="True" CommandArgument="">
<asp:ListItem>Pendiente</asp:ListItem>
<asp:ListItem>Atendido</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Atender" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnAtender" runat="server"
CommandArgument='<%# Eval("idCita")%>' CommandName="Atender"
ImageUrl="~/img/activar.png" Width="16px" Height="16px"
onclientclick="return confirm('¿Desea marcar como atendido este registro?');" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CRM" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnCRM" runat="server"
CommandArgument='<%# Eval("IdCliente")%>' CommandName="CRM"
ImageUrl="~/img/go.gif" Width="16px" Height="16px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VM" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnVerMas" runat="server"
CommandArgument='<%# Eval("IdCliente")%>' CommandName="VerMas"
ImageUrl="~/img/search.png" Width="16px" Height="16px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" Font-Size="Small" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Larger" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" Font-Size="Small" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
在我的cs中我有...
private static string strColorUrgente = "#FF525D";
private static string strColorEnCurso = "#FFDE00";
private static string strColorHoy = "#3ECF00";
这是 rowbounddata 函数
protected void grdvEventosVendedor_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0 && e.Row.Cells[11].Text == "Pendiente")
{
string strFecha = (e.Row.FindControl("lblFecha") as Label).Text;
int intYear = Convert.ToInt32(strFecha.Split('/')[2]);
int intMonth = Convert.ToInt32(strFecha.Split('/')[1]);
int intDay = Convert.ToInt32(strFecha.Split('/')[0]);
DateTime dtmFecha = new DateTime(intYear, intMonth, intDay);
if (dtmFecha < DateTime.Today)
{
e.Row.BackColor = Color.FromName(strColorUrgente);
}
else if (dtmFecha == DateTime.Today)
{
DateTime dtmHoraInicio = Convert.ToDateTime(e.Row.Cells[9].Text);
if (dtmHoraInicio > DateTime.Now)
{
e.Row.BackColor = Color.FromName(strColorHoy);
}
else
{
e.Row.BackColor = Color.FromName(strColorEnCurso);
}
}
}
}
每当我进入此页面或使用搜索引擎时,我都会使用数据源刷新 gridview,当然,RowDataBound 会被触发...最终某些行的颜色会发生变化...
您会注意到在 gridview 中,在最后一列上有一个名为 imgBtnVerMas 的按钮...
按下时,会触发下面的功能
string strMensaje = "";
try
{
//Method that brings back data from a specific client (returns a datatable)
//intIdCliente was defined in the CommandArgument
DataTable dtDatosCliente = ConexionBD.GetInstanciaConexionBD().GetClienteEspecifico2(intIdCliente);
//Assigning to a string a message that needs info from the previous datatable
strMensaje += "DATOS DEL CLIENTE\\n\\nNombre:\\t" + dtDatosCliente.Rows[0]["Cliente"] + "\\nEmpresa: " + dtDatosCliente.Rows[0]["Empresa"];
}
catch
{
if (strMensaje == "")
{
strMensaje = "Hubo Un Error Al Traer Los Datos Del Cliente";
}
else
{
strMensaje += "\n\nERROR!!!!!!!";
}
}
ClientScript.RegisterStartupScript(this.GetType(), "Mensaje", "alert('" + strMensaje + "');", true);
之后,显示了消息,但是,所有行的颜色都消失了......我想知道......即使在回发后我怎样才能保持 gridview 行的颜色......
谢谢
最佳答案
您需要在 onprerender
事件上设置颜色,而不是在 RowDataBound 上设置颜色,因此在 GridView 上设置事件
onprerender="gvMyLista_PreRender"
和代码背后
protected void gvMyLista_PreRender(object sender, EventArgs e)
{
// loop your data, and fix your colors.
for (int i = 0; i < gvMyLista.Rows.Count; i++)
{
// get your data as...
// gvMyLista.Rows[i].Cells[2].Text
}
}
关于c# - 回发后如何在 gridview 上保留颜色? ASP.NET C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12042725/
我有一个需要以编程方式作为列(而不是行)绑定(bind)到 gridview 的值列表。例如,如果我的 DAL 返回 10 个值,我需要将这 10 个值显示为 gridview 中的列作为标题文本,并
我有一个使用 out-gridview 显示结果的脚本.这是一个简单的例子: "hello world" | out-gridview 当我使用 Run with PowerShell 运行脚本时,它
我正在尝试使用工作正常的 Kartik 导出小部件,除了它没有在扩展“函数/网格”中获取数据。现在我当然明白它是如何工作的,它实际上并没有显示任何东西,只是呈现另一个 View 。但我不知道如何在导出
在 Android 教程中,GridView tutorial准确的说是有一行代码 GridView gridview = (GridView) findViewById(R.id.gridview)
我正在尝试为与我的 gridview 关联的每一列添加一个标题,这样当页面足够宽以显示多行项目时,列标题应该显示在每一列的顶部,如果页面缩小,以至于该列不再适合。 最终结果看起来像这样: 2 colu
在我使用 comboBox 而不是 default(textBox) 在 gridview 中使用这个搜索之前: [ 'attribute' => 'project_status',
我想在列中显示我的交易表中一个/所有帐户的总余额。余额列应显示添加上一行总余额的余额。 我的网格 View 代码是 'yii\grid\SerialColumn'],
我正在使用 gridview 列出我的所有数据。我的 table 看起来像这样。 $dataProvider, 'columns' => [ 'firstName',
我目前正在构建一个 Windows 8 XAML C# 应用程序。在一个页面中,我有一个用于水平滑动和滚动的滚动查看器。我有几个控件可以很好地与 scorllviewer 配合使用。但是当您滚动并且光
当调整 GridView 的大小时,它的元素被重新排列,该元素的动画似乎不起作用。 在这里你可以找到一个简单的例子:http://pastebin.com/BgST6sCv 如果单击示例中的其中一个方
如何动态更改 gridview 模板列顺序? 最佳答案 迭代 通通栏目 的网格 View 对象和 店铺 他们在 收藏 . List columns = new List(); foreach (Dat
我在 Yii2 中使用了 CRUD 生成器,它为我的 actionIndex 生成了以下代码 Controller ... public function actionIndex() { $s
在我的用户模型中我有一个函数: public function getRole() { if ($this->role == self::ROLE_USER) { return
我正在构建一个带有 Yii2 框架的 webapp,它将为用户(登录)提供下载管理员预先上传文件的能力。 我已经创建了操作 actionDownload在调用 sendFile() 的特定 Contr
我想在 GridView 中订购图像。我已经使用列表框并成功将图像添加到其中。它的显示如下 但我希望这些图像显示在 GridView 中。可能与否。 请帮助我......提前致谢 最佳答案 出于此类目
我试图通过在 QtQuick 2.0 (Qt 5) 中动态填充 ListModel 来填充 GridView。它可以工作,但应用程序启动速度非常慢: 应用程序窗口立即出现,但大约需要 2 秒才会出现浅
我在 Yii2 GridView 小部件中显示一些列,“执行人员名称”是其中之一,但它应该仅在主管登录时显示,而不是在执行人员登录时显示。 当我将可见值硬编码为零时,它不会显示如下: [ 'l
我想用 HTML 制作一个表格。所以我从数据库中获取了一些数据。 每个项目都是一个用户。用户有用户名、名字、姓氏和电子邮件。我想制作一个表格来列出这些用户。 每个用户都必须换行。我已经在互联网上搜索过
我想在 pjax 处于事件状态的排序 gridview 之后运行脚本。重新加载 gridview 后我找不到任何事件处理程序。 pjax调用和gridview刷新后有没有正确的事件处理方法? 最佳答案
在 WinRT 上,我有一个 GridView 。我想在到达 gridview 的末尾时执行一个方法。 但是,没有像 GridView 那样的事件方法。 我尝试检测对 gridview 的操纵,但似乎
我是一名优秀的程序员,十分优秀!