[Mono-list] ASP.NET: DataGrid bug !?

Tiago Lima tiago.lima@vianw.pt
Thu, 16 Oct 2003 16:19:32 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0203_01C39401.4806CFF0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi again,

Mono, I have a problem. :)

It appears that the DataGrid control doesn't do "paging" (or custom paging)
I guess...
Maybe I am doing something wrong, but can you check this ? perhaps in cvs is
corrected, no?
When clicking the "table page number" on the bottom of the datagrid table it
doesn't change the "table page" to the selected one...

In Suse8.2:
Using all latest RPMs!! NOT from cvs !!
    # mono --version
    Mono JIT compiler version 0.28, (C) 2002, 2003 Ximian, Inc.

    # mcs --version
    Mono C# compiler version 0.27.0.0

    XSP-0.6

Thanks in advance,
    Tiago Lima

------=_NextPart_000_0203_01C39401.4806CFF0
Content-Type: application/octet-stream;
	name="DataGridTest.aspx"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="DataGridTest.aspx"

<%@ Page Language=3D"C#" CodeBehind=3D"DataGridTest.ascx.cs" =
Inherits=3D"DataGridTests.DataGridTester" %>

<form method=3D"post" runat=3D"server">
	<asp:DataGrid id=3D"_dataGrid"
				  AutoGenerateColumns=3D"false"
				  GridLines=3D"Both"
				  ShowHeader=3D"true"
				  BorderWidth=3D"1px"
				  PageSize=3D"5"
				  AllowPaging=3D"True"
				  AllowCustomPaging=3D"True"
				  CellPadding=3D"3"
				  runat=3D"server">
	=09
		<HeaderStyle HorizontalAlign=3D"Center" BackColor=3D"#dddddd">
	    </HeaderStyle>
	=09
		<PagerStyle Mode=3D"NumericPages"
					HorizontalAlign=3D"Right">
		</PagerStyle>
	=09
		<Columns>
			<asp:BoundColumn DataField=3D"ID" Visible=3D"false" />
			<asp:ButtonColumn ButtonType=3D"PushButton" CommandName=3D"add" =
HeaderText=3D"Action" Text=3D"Add" />
		</Columns>
	=09
	</asp:DataGrid>
</form>

------=_NextPart_000_0203_01C39401.4806CFF0
Content-Type: application/octet-stream;
	name="DataGridTest.aspx.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="DataGridTest.aspx.cs"


using Npgsql;

using System;
using System.Data;
using System.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;

namespace DataGridTests
{
	public class DataGridTester : Page
	{
		protected DataGrid _newsResourcesGrid;
	=09
		protected DataGrid _dataGrid;
		protected Image _image;
	=09
		protected long _intStartIndex;
		protected long _intEndIndex;
	=09
		private void Page_Load(object sender, EventArgs args)
		{
			if(!IsPostBack)
			{
				_dataGrid.VirtualItemCount =3D 12;
				BindDataGrid();
			}
		=09
			_dataGrid.ItemCommand +=3D new =
DataGridCommandEventHandler(OnItemCommand);
			_dataGrid.PageIndexChanged +=3D new =
DataGridPageChangedEventHandler(OnPageIndexChanged);
		}
		private void OnPageIndexChanged(object sender, =
DataGridPageChangedEventArgs args)
		{
			// Changes the page.
			_intStartIndex =3D (args.NewPageIndex * _dataGrid.PageSize);
			_dataGrid.CurrentPageIndex =3D args.NewPageIndex;
			BindDataGrid();
		}
		private void BindDataGrid()
		{
			_intEndIndex =3D _intStartIndex + _dataGrid.PageSize;
			NpgsqlConnection local =3D GetLocalConnection();
			local.Open();
		=09
			Npgsql.NpgsqlCommand command =3D new Npgsql.NpgsqlCommand(
				"SELECT ID, IDTipo, descricao, recurso " +
				"FROM RecursoMultimedia " +
				"WHERE (ID > :startIndex) AND (ID <=3D :endIndex) " +
				"ORDER BY ID",
				local);
		=09
			NpgsqlParameter param1 =3D new NpgsqlParameter("startIndex", =
System.Data.DbType.Int64);
			param1.Value =3D _intStartIndex;
			NpgsqlParameter param2 =3D new NpgsqlParameter("endIndex", =
System.Data.DbType.Int64);
			param2.Value =3D _intEndIndex;
		=09
			command.Parameters.Add(param1);
			command.Parameters.Add(param2);
		=09
			NpgsqlDataAdapter adapter =3D new NpgsqlDataAdapter(command);
			DataSet dataSet =3D new DataSet();
			adapter.Fill(dataSet);
		=09
			_dataGrid.DataSource =3D dataSet;
			_dataGrid.DataBind();
		}
		private void OnItemCommand(object sender, DataGridCommandEventArgs e)
		{
			if (e.CommandName =3D=3D "add")
			{
				DataGridItem item =3D e.Item;
				string id =3D item.Cells[0].Text;
				Controls.Add(new LiteralControl("ID =3D " + id));
			}
		}
		private NpgsqlConnection GetLocalConnection()
		{
			return new NpgsqlConnection("Server=3D192.168.8.6;Port=3D5432;User =
Id=3Duser;Password=3D;Database=3Ddatabase;");
		}
	}
}

------=_NextPart_000_0203_01C39401.4806CFF0--