Jump to content

Recommended Posts

Posted

Boas pessoal,

Estou com um problema meio estranho. Tenho uma pagina em c# asp.net onde tenho uma gridview que apresenta dados de uma base de dados postgres. no meu codigo c# programo a gridview e ao executar o código, a pagina abre apresentado a gridview com os dados da BD.

O problema está quando acrescento uma função para pintar as linhas da gridview segundo determinada condição, ao executar o código a pagina abre e fica toda a vida a "pensar" até que dá timeout e não apresenta nada.

O meu codigo c# é:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Npgsql;//database
using System.Drawing;
using System.Data.SqlClient;
using System.Configuration;

public partial class Account_Login : System.Web.UI.Page
{
// mostra a tabela inteira
protected void Page_Load(object sender, EventArgs e)
{
	if (!Request.IsAuthenticated)//não autenticado
	{
		Response.Redirect("~/Account/Login.aspx");
	}
	if (Request.IsAuthenticated)//autenticado
	{
		refresh_logistics_table();
	}

}
public void refresh_logistics_table()
{
	DataBase.Conecta();
	Npgsql.NpgsqlCommand comm = new Npgsql.NpgsqlCommand();
	comm.CommandText = "SELECT material, line, date_time_request, requested_by, delivered FROM logistics_request";
	comm.Connection = DataBase.Conn;
	Npgsql.NpgsqlDataAdapter myDataAdapter = new Npgsql.NpgsqlDataAdapter();
	myDataAdapter.SelectCommand = comm;
	DataSet myDataSet = new DataSet();
	int user_exist = myDataAdapter.Fill(myDataSet);
	Panel_gridview_logistics.Visible = true;
	GridView_logistics.DataSource = myDataSet;
	GridView_logistics.DataBind();

	DataBase.Desconecta();
}


 protected void row_paint(object sender, GridViewRowEventArgs e)
{

	if (e.Row.RowType == DataControlRowType.DataRow)  
   {
	   string delivered = DataBinder.Eval(e.Row.DataItem, "delivered").ToString();

	  if (delivered == "TRUE")  
		{
			e.Row.BackColor = Color.LightGreen;
		}
		else
		{
			e.Row.BackColor = Color.LightPink;
		}
	}

	refresh_logistics_table();
}

Sem a função row_paint funciona lindamente.

o meu aspx esta assim:

<%@ Page Title="Missing material" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="list_of_material.aspx.cs" Inherits="Account_Login" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2 align="center">
	MISSING MATERIAL</h2>
<asp:Panel ID="Panel_Search_Project" runat="server" HorizontalAlign="Center" ScrollBars="Auto"
	EnableViewState="True">
	<p>
		    
	</p>
</asp:Panel>
<asp:Panel ID="Panel_gridview_logistics" runat="server"
	HorizontalAlign="Center">
	<asp:GridView ID="GridView_logistics" runat="server" HorizontalAlign="Center" BackColor="White"
		BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
		AutoGenerateColumns="False" AutoGenerateDeleteButton="True" OnRowDataBound="row_paint"
		AutoGenerateEditButton="False" GridLines="Vertical" ShowFooter="True"
		AllowPaging="True">
		<AlternatingRowStyle BackColor="White" />
		<Columns>
			<asp:TemplateField HeaderText="Missing material">
				<%--<EditItemTemplate>
					<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
				</EditItemTemplate>--%>
				<ItemTemplate>
					<asp:Label ID="Label1" Text='<%# Eval("material") %>'
						runat="server"></asp:Label>
				</ItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Line" InsertVisible="False">
				<%--<EditItemTemplate>
					<asp:CheckBox ID="CheckBox1" runat="server" />
				</EditItemTemplate>--%>
				<ItemTemplate>
					<asp:Label ID="Label1" runat="server" Text='<%# Eval("line") %>'></asp:Label>
				</ItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Date / Time request">
				<ItemTemplate>
					<asp:Label ID="Label1" runat="server" Text='<%# Eval("date_time_request") %>'></asp:Label>
				</ItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Requested by">
				<ItemTemplate>
					<asp:Label ID="Label1" runat="server"
						Text='<%# Eval("requested_by") %>'></asp:Label>
				</ItemTemplate>
			</asp:TemplateField>
			<asp:TemplateField HeaderText="Delivered">
				<ItemTemplate>
					<asp:Label ID="Label1" runat="server" Text='<%# Eval("delivered") %>'></asp:Label>
				</ItemTemplate>
			</asp:TemplateField>
		</Columns>
		<FooterStyle BackColor="#565656" />
		<HeaderStyle BackColor="#565656" ForeColor="White" HorizontalAlign="Center"
			VerticalAlign="Middle" />
		<PagerSettings Mode="NextPrevious" />
		<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Center" />
		<RowStyle BackColor="White" />
		<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
		<SortedAscendingCellStyle BackColor="#FBFBF2" />
		<SortedAscendingHeaderStyle BackColor="#848384" />
		<SortedDescendingCellStyle BackColor="#EAEAD3" />
		<SortedDescendingHeaderStyle BackColor="#575357" />
	</asp:GridView>
</asp:Panel>
</asp:Content>

Alguém me consegue ajudar nesta situação pf?

Posted (edited)

comentei a função refresh_logistics_table() e a pagina já aparece colorida, mas aparece toda a lightpink mesmo que a condição seja verdadeira para lightgreen.

Que estou a fazer de errado?

protected void row_paint(object sender, GridViewRowEventArgs e)
{
	if (e.Row.RowType == DataControlRowType.DataRow)
	{
		string celula = e.Row.Cells[5].ToString();
		if (celula == "TRUE")  
		{
			e.Row.BackColor = Color.LightGreen;
		}
		else
		{
			e.Row.BackColor = Color.LightPink;
		}
	}
   // refresh_logistics_table();
}
Edited by apocsantos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.