public void DataSourceIDBindingManualColumns () 
		{
			Page page = new Page ();
			DataGridPoker dg = new DataGridPoker ();
			dg.ID = "DataGrid";
			dg.AutoGenerateColumns = false;
			BoundColumn col = new BoundColumn();
			col.DataField = "something";
			dg.Columns.Add (col);

			page.Controls.Add (dg);

			DataTable dt = new DataTable ();
			dt.Columns.Add (new DataColumn ("something", typeof (Int32)));
			DataRow dr = dt.NewRow ();
			dt.Rows.Add (new object [] { 1 });
			dt.Rows.Add (new object [] { 2 });
			dt.Rows.Add (new object [] { 3 });
			dt.Rows.Add (new object [] { 4 });
			dt.Rows.Add (new object [] { 5 });
			dt.Rows.Add (new object [] { 6 });

			DataView dv = new DataView (dt);

			dg.DataSource = dv;
			dg.DataBind ();

			Assert.AreEqual (1, dg.Columns.Count, "Columns Count");
			Assert.AreEqual (6, dg.Items.Count, "Items Count");
			Assert.AreEqual ("1", dg.Items[0].Cells[0].Text, "Cell content");
		}
		public void BubbleEvent ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataGridCommandEventArgs command_args;

			//
			// Cancel
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Cancel", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.CancelCommand += new DataGridCommandEventHandler (CancelCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (cancel_command, "A1");
			Assert.IsTrue (item_command, "#01");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("cancel", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.CancelCommand += new DataGridCommandEventHandler (CancelCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (cancel_command, "A2");
			Assert.IsTrue (item_command, "#02");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("CANCEL", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.CancelCommand += new DataGridCommandEventHandler (CancelCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (cancel_command, "A3");
			Assert.IsTrue (item_command, "#03");

			//
			// Delete
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Delete", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DeleteCommand += new DataGridCommandEventHandler (DeleteCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (delete_command, "A4");
			Assert.IsTrue (item_command, "#04");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("delete", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DeleteCommand += new DataGridCommandEventHandler (DeleteCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (delete_command, "A5");
			Assert.IsTrue (item_command, "#05");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("DELETE", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DeleteCommand += new DataGridCommandEventHandler (DeleteCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (delete_command, "A6");
			Assert.IsTrue (item_command, "#06");

			//
			// Edit
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Edit", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.EditCommand += new DataGridCommandEventHandler (EditCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (edit_command, "A7");
			Assert.IsTrue (item_command, "#07");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("edit", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.EditCommand += new DataGridCommandEventHandler (EditCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (edit_command, "A8");
			Assert.IsTrue (item_command, "#08");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("EDIT", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.EditCommand += new DataGridCommandEventHandler (EditCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (edit_command, "A9");
			Assert.IsTrue (item_command, "#09");

			//
			// Item
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Item", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (item_command, "A10");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("item", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (item_command, "A11");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("ITEM", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (item_command, "A12");

			//
			// Sort
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Sort", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SortCommand += new DataGridSortCommandEventHandler (SortCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (sort_command, "A13");
			Assert.IsTrue (item_command, "#10");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("sort", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SortCommand += new DataGridSortCommandEventHandler (SortCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (sort_command, "A14");
			Assert.IsTrue (item_command, "#11");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("SORT", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SortCommand += new DataGridSortCommandEventHandler (SortCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (sort_command, "A15");
			Assert.IsTrue (item_command, "#12");

			//
			// Update
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("Update", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.UpdateCommand += new DataGridCommandEventHandler (UpdateCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (update_command, "A16");
			Assert.IsTrue (item_command, "#13");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("update", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.UpdateCommand += new DataGridCommandEventHandler (UpdateCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (update_command, "A17");
			Assert.IsTrue (item_command, "#14");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs ("UPDATE", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.UpdateCommand += new DataGridCommandEventHandler (UpdateCommandHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (update_command, "A18");
			Assert.IsTrue (item_command, "#15");

			//
			// Select
			//
			DataGridItem item = new DataGridItem (0, 0, ListItemType.Item);
			
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Select", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SelectedIndexChanged += new EventHandler (SelectedIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (selected_changed, "A19");
			Assert.IsTrue (item_command, "#16");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("select", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SelectedIndexChanged += new EventHandler (SelectedIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (selected_changed, "A20");
			Assert.IsTrue (item_command, "#17");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("SELECT", String.Empty));
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.SelectedIndexChanged += new EventHandler (SelectedIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (selected_changed, "A21");
			Assert.IsTrue (item_command, "#18");
		}
		public void BadBubblePageArg2 ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataGridItem item = new DataGridItem (0, 0, ListItemType.Item);
			DataGridCommandEventArgs command_args;

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Page", new object ()));

			p.DoBubbleEvent (this, command_args);
		}
		public void SelectItemOutOfRange ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataGridItem d;

			p.SelectedIndex = 25;
			d = p.SelectedItem;
		}
		public void Styles ()
		{
			DataGridPoker p = new DataGridPoker ();
			StateBag vs = p.GetViewState ();
			
			p.BackImageUrl = "foobar url";

			// The styles get stored in the view state
			Assert.AreEqual (vs.Count, 0, "A1");
			Assert.IsNull (vs ["BackImageUrl"], "A2");
			Assert.IsNull (vs ["GridLines"], "A3");
			Assert.IsNull (vs ["CellSpacing"], "A4");
		}
		public void SelectedIndexTooLow ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.SelectedIndex = -2;
		}
		public void ViewState ()
		{
			DataGridPoker p = new DataGridPoker ();
			StateBag vs = p.GetViewState ();

			Assert.AreEqual (vs.Count, 0, "A1");

			p.AllowCustomPaging = true;
			Assert.AreEqual (vs.Count, 1, "A2");
			Assert.AreEqual (vs ["AllowCustomPaging"], true, "A3");
			p.AllowCustomPaging = false;
			Assert.AreEqual (vs.Count, 1, "A4");
			Assert.AreEqual (vs ["AllowCustomPaging"], false, "A5");

			p.AllowPaging = true;
			Assert.AreEqual (vs.Count, 2, "A6");
			Assert.AreEqual (vs ["AllowPaging"], true, "A7");
			p.AllowPaging = false;
			Assert.AreEqual (vs.Count, 2, "A8");
			Assert.AreEqual (vs ["AllowPaging"], false, "A9");

			p.AllowSorting = true;
			Assert.AreEqual (vs.Count, 3, "A10");
			Assert.AreEqual (vs ["AllowSorting"], true, "A11");
			p.AllowSorting = false;
			Assert.AreEqual (vs.Count, 3, "A12");
			Assert.AreEqual (vs ["AllowSorting"], false, "A13");

			p.AutoGenerateColumns = true;
			Assert.AreEqual (vs.Count, 4, "A14");
			Assert.AreEqual (vs ["AutoGenerateColumns"], true, "A15");
			p.AutoGenerateColumns = false;
			Assert.AreEqual (vs.Count, 4, "A16");
			Assert.AreEqual (vs ["AutoGenerateColumns"], false, "A17");

			p.CurrentPageIndex = 1;
			Assert.AreEqual (vs.Count, 5, "A18");
			Assert.AreEqual (vs ["CurrentPageIndex"], 1, "A19");

			p.EditItemIndex = 1;
			Assert.AreEqual (vs.Count, 6, "A20");
			Assert.AreEqual (vs ["EditItemIndex"], 1, "A20");

			p.PageSize = 25;
			Assert.AreEqual (vs.Count, 7, "A21");
			Assert.AreEqual (vs ["PageSize"], 25, "A22");

			p.SelectedIndex = 25;
			Assert.AreEqual (vs.Count, 8, "A23");
			Assert.AreEqual (vs ["SelectedIndex"], 25, "A24");

			p.ShowFooter = false;
			Assert.AreEqual (vs.Count, 9, "A25");
			Assert.AreEqual (vs ["ShowFooter"], false, "A26");
			p.ShowFooter = true;
			Assert.AreEqual (vs ["ShowFooter"], true, "A27");

			p.ShowHeader = false;
			Assert.AreEqual (vs.Count, 10, "A28");
			Assert.AreEqual (vs ["ShowHeader"], false, "A29");
			p.ShowHeader = true;
			Assert.AreEqual (vs ["ShowHeader"], true, "A30");

			p.VirtualItemCount = 100;
			Assert.AreEqual (vs.Count, 11, "A31");
			Assert.AreEqual (vs ["VirtualItemCount"], 100, "A32");
		}
		public void CreationEvents ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataTable table = new DataTable ();

			table.Columns.Add (new DataColumn ("one", typeof (string)));
			table.Columns.Add (new DataColumn ("two", typeof (string)));
			table.Columns.Add (new DataColumn ("three", typeof (string)));
			
			p.DataSource = new DataView (table);

			p.ItemCreated += new DataGridItemEventHandler (ItemCreatedHandler);
			p.ItemDataBound += new DataGridItemEventHandler (ItemDataBoundHandler);

			// No items added yet
			ResetEvents ();
			p.CreateControls (true);
			Assert.IsTrue (item_created, "A1");
			Assert.IsTrue (item_data_bound, "A2");

			table.Rows.Add (new object [] { "1", "2", "3" });

			ResetEvents ();
			p.CreateControls (true);
			Assert.IsTrue (item_created, "A3");
			Assert.IsTrue (item_data_bound, "A4");

			// no databinding
			ResetEvents ();
			p.CreateControls (false);
			Assert.IsTrue (item_created, "A5");
			Assert.IsFalse (item_data_bound, "A6");
		}
		public void InitializePager ()
		{
			DataGridPoker p = new DataGridPoker ();
			PagedDataSource paged = new PagedDataSource ();
			DataTable table = new DataTable ();
			DataGridItem item = new DataGridItem (-1, -1, ListItemType.Pager);
			ArrayList columns;
			LinkButton next;
			LinkButton prev;

			table.Columns.Add (new DataColumn ("one", typeof (string)));
			table.Columns.Add (new DataColumn ("two", typeof (string)));
			table.Columns.Add (new DataColumn ("three", typeof (string)));

			for (int i = 0; i < 25; i++)
				table.Rows.Add (new object [] { "1", "2", "3" });
			paged.DataSource = new DataView (table);

			columns = p.CreateColumns (paged, true);
			p.InitPager (item, columns.Count, paged);

			//
			// No where to go
			//

			Assert.AreEqual (item.Controls.Count, 1, "A1");
			Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A2");
			Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A3");
			Assert.AreEqual (item.Controls [0].Controls [0].GetType (), typeof (Label), "A4");
			Assert.AreEqual (item.Controls [0].Controls [1].GetType (),
					typeof (LiteralControl), "A5");
			Assert.AreEqual (item.Controls [0].Controls [2].GetType (), typeof (Label), "A6");
			Assert.AreEqual (((Label) item.Controls [0].Controls [0]).Text, "&lt;", "A7");
			Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text,
					"&nbsp;", "A7");
			Assert.AreEqual (((Label) item.Controls [0].Controls [2]).Text, "&gt;", "A8");

			//
			// Next
			//

			item = new DataGridItem (-1, -1, ListItemType.Pager);
			paged.PageSize = 5;
			paged.VirtualCount = 25;
			paged.AllowPaging = true;
			p.InitPager (item, columns.Count, paged);

			Assert.AreEqual (item.Controls.Count, 1, "A9");
			Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A10");
			Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A11");
			Assert.AreEqual (item.Controls [0].Controls [0].GetType (), typeof (Label), "A12");
			Assert.AreEqual (item.Controls [0].Controls [1].GetType (),
					typeof (LiteralControl), "A13");
			Assert.AreEqual (((Label) item.Controls [0].Controls [0]).Text, "&lt;", "A14");
			Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text,
					"&nbsp;", "A16");

			next = (LinkButton) item.Controls [0].Controls [2];
			Assert.AreEqual (next.Text, "&gt;", "A17");
			Assert.AreEqual (next.CommandName, "Page", "A18");
			Assert.AreEqual (next.CommandArgument, "Next", "A19");


			//
			// Both
			//

			item = new DataGridItem (-1, -1, ListItemType.Pager);
			paged.PageSize = 5;
			paged.VirtualCount = 25;
			paged.AllowPaging = true;
			paged.CurrentPageIndex = 2;
			p.InitPager (item, columns.Count, paged);

			Assert.AreEqual (item.Controls.Count, 1, "A20");
			Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A21");
			Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A22");
			Assert.AreEqual (item.Controls [0].Controls [1].GetType (),
					typeof (LiteralControl), "A23");
			Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text,
					"&nbsp;", "A24");

			// This is failing with an invalidcast right now. It's something related to
			// the pager thinking that it's on the last page and rendering a label instead
			next = (LinkButton) item.Controls [0].Controls [2];
			Assert.AreEqual (next.Text, "&gt;", "A25");
			Assert.AreEqual (next.CommandName, "Page", "A26");
			Assert.AreEqual (next.CommandArgument, "Next", "A27");

			prev = (LinkButton) item.Controls [0].Controls [0];
			Assert.AreEqual (prev.Text, "&lt;", "A28");
			Assert.AreEqual (prev.CommandName, "Page", "A29");
			Assert.AreEqual (prev.CommandArgument, "Prev", "A30");

			//
			// Back only
			//

			item = new DataGridItem (-1, -1, ListItemType.Pager);
			paged.PageSize = 5;
			paged.VirtualCount = 25;
			paged.AllowPaging = true;
			paged.CurrentPageIndex = 4;
			p.InitPager (item, columns.Count, paged);

			Assert.AreEqual (item.Controls.Count, 1, "A31");
			Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A32");
			Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A33");
			Assert.AreEqual (item.Controls [0].Controls [1].GetType (),
					typeof (LiteralControl), "A34");
			Assert.AreEqual (item.Controls [0].Controls [2].GetType (), typeof (Label), "A35");
			Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text,
					"&nbsp;", "A36");
			Assert.AreEqual (((Label) item.Controls [0].Controls [2]).Text, "&gt;", "A37");

			prev = (LinkButton) item.Controls [0].Controls [0];
			Assert.AreEqual (prev.Text, "&lt;", "A38");
			Assert.AreEqual (prev.CommandName, "Page", "A39");
			Assert.AreEqual (prev.CommandArgument, "Prev", "A40");

		}
		public void Defaults ()
		{
			DataGridPoker p = new DataGridPoker ();

			Assert.AreEqual (DataGrid.CancelCommandName, "Cancel", "A1");
			Assert.AreEqual (DataGrid.DeleteCommandName, "Delete", "A2");
			Assert.AreEqual (DataGrid.EditCommandName, "Edit", "A3");
			Assert.AreEqual (DataGrid.NextPageCommandArgument, "Next", "A4");
			Assert.AreEqual (DataGrid.PageCommandName, "Page", "A5");
			Assert.AreEqual (DataGrid.PrevPageCommandArgument, "Prev", "A6");
			Assert.AreEqual (DataGrid.SelectCommandName, "Select", "A7");
			Assert.AreEqual (DataGrid.SortCommandName, "Sort", "A8");
			Assert.AreEqual (DataGrid.UpdateCommandName, "Update", "A9");

			Assert.AreEqual (p.AllowCustomPaging, false, "A10");
			Assert.AreEqual (p.AllowPaging, false, "A11");
			Assert.AreEqual (p.AllowSorting, false, "A12");
			Assert.AreEqual (p.AutoGenerateColumns, true, "A13");
			Assert.AreEqual (p.BackImageUrl, String.Empty, "A14");
			Assert.AreEqual (p.CurrentPageIndex, 0, "A15");
			Assert.AreEqual (p.EditItemIndex, -1, "A16");
			Assert.AreEqual (p.PageCount, 0, "A17");
			Assert.AreEqual (p.PageSize, 10, "A18");
			Assert.AreEqual (p.SelectedIndex, -1, "A19");
			Assert.AreEqual (p.SelectedItem, null, "A20");
			Assert.AreEqual (p.ShowFooter, false, "A21");
			Assert.AreEqual (p.ShowHeader, true, "A22");
			Assert.AreEqual (p.VirtualItemCount, 0, "A23");
		}
		public void CreateControls ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataTable table = new DataTable ();

			table.Columns.Add (new DataColumn ("one", typeof (string)));
			table.Columns.Add (new DataColumn ("two", typeof (string)));
			table.Columns.Add (new DataColumn ("three", typeof (string)));
			table.Rows.Add (new object [] { "1", "2", "3" });
			
			p.DataSource = new DataView (table);

			p.CreateControls (true);
			Assert.AreEqual (p.Controls.Count, 1, "A1");

			ShowControlsRecursive (p.Controls [0], 1);
		}
		public void OneTemplateColumn3 ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.ShowFooter = true;
			p.AutoGenerateColumns = false;
			p.DataSource = new ArrayList ();
			TemplateColumn tc = new TemplateColumn ();
			tc.FooterTemplate = new MyTemplate ("hola");
			p.Columns.Add (tc);
			p.DataBind ();

			StringWriter sw = new StringWriter ();
			HtmlTextWriter tw = new HtmlTextWriter (sw);
			Assert.AreEqual (1, p.Columns.Count, "columns");
			Assert.AreEqual (1, p.Controls.Count, "controls");

			string render = p.Render ();
			// no items, but we have a footer
			Assert.IsTrue (-1 != render.IndexOf ("hola"), "template");
		}
		public void OneTemplateColumn2 ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.ShowFooter = true;
			p.AutoGenerateColumns = false;
			p.DataSource = new ArrayList ();
			TemplateColumn tc = new TemplateColumn ();
			tc.HeaderText = " ";
			tc.FooterTemplate = new MyTemplate ("hola");
			p.Columns.Add (tc);
			Assert.AreEqual (1, p.Columns.Count, "columns-1");
			Assert.AreEqual (0, p.Controls.Count, "controls-1");
			p.CreateControls (true);
			// This time we have the table there. Thanks to the empty ArrayList
			Assert.AreEqual (1, p.Columns.Count, "columns-2");
			Assert.AreEqual (1, p.Controls.Count, "controls-2");
			p.PrepareCH ();
			Assert.AreEqual (1, p.Columns.Count, "columns-3");
			Assert.AreEqual (1, p.Controls.Count, "controls-3");
		}
		public void OneTemplateColumn1 ()
		{
			DataGridPoker p = new DataGridPoker ();
			TemplateColumn tc = new TemplateColumn ();
			tc.ItemTemplate = new MyTemplate ("hola");
			p.Columns.Add (tc);
			ControlCollection controls = p.Controls;
			p.CreateControls (true);
			Assert.AreEqual (1, p.Columns.Count, "columns");
			Assert.AreEqual (0, controls.Count, "controls");
			string render = p.Render ();
			// no items, even with a templated column.
			// The table is not added if DataSource == null
			Assert.IsTrue (-1 == render.IndexOf ("hola"), "template");
		}
		public void EditItemIndexTooLow ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.EditItemIndex = -2;
		}
		public void Render ()
		{
			DataGridPoker p = new DataGridPoker ();

			Assert.AreEqual (p.Render (), String.Empty, "A1");
		}
		public void PageSizeTooLow ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.PageSize = 0;
		}
		public void SpecialLinkButton1 ()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add (new DataColumn("something", typeof(Int32)));
			DataRow dr = dt.NewRow ();
			dt.Rows.Add (new object [] { 1 });
			DataView dv = new DataView (dt);
			DataGridPoker dg = new DataGridPoker ();
			dg.AllowSorting = true;
			dg.HeaderStyle.Font.Bold = true;
			dg.HeaderStyle.ForeColor = Color.FromArgb (255,255,255,255);
			dg.HeaderStyle.BackColor = Color.FromArgb (33,33,33,33);
			dg.DataSource = dv;
			dg.DataBind ();
			LinkButton lb = (LinkButton) FindByType (dg.Controls [0], typeof (LinkButton));
			Assert.IsNotNull (lb, "lb");
			StringWriter sr = new StringWriter ();
			HtmlTextWriter output = new HtmlTextWriter (sr);
			// Nothing here...
			Assert.AreEqual (Color.Empty, lb.ControlStyle.ForeColor, "fore");
			lb.RenderControl (output);
			// Nothing here...
			Assert.AreEqual (Color.Empty, lb.ControlStyle.ForeColor, "fore2");
			dg.Render ();
			// Surprise! after rendering the datagrid, the linkbutton has the ForeColor from the datagrid
			Assert.AreEqual (Color.FromArgb (255,255,255,255), lb.ControlStyle.ForeColor, "fore3");

			// Extra. Items != empty
			Assert.AreEqual (1, dg.Items.Count, "itemCount");
		}
		public void VirtualItemCountTooLow ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.VirtualItemCount = -1;
		}
		public void SpecialLinkButton2 ()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add (new DataColumn("string_col", typeof(string)));
			DataRow dr = dt.NewRow ();
			dt.Rows.Add (new object [] { "Item 1" });
			DataView dv = new DataView (dt);

			DataGridPoker dg = new DataGridPoker ();
			dg.DataSource = dv;
			dg.AutoGenerateColumns = false;
			dg.HeaderStyle.ForeColor = Color.FromArgb (255,255,255,255);
			dg.HeaderStyle.BackColor = Color.FromArgb (33,33,33,33);

			ButtonColumn bc = new ButtonColumn ();
			bc.HeaderText = "Some header";
			bc.DataTextField = "string_col";
			bc.CommandName = "lalala";
			dg.Columns.Add (bc);

			BoundColumn bound = new BoundColumn ();
			bound.HeaderText = "The other column";
			bound.DataField = "string_col";
			dg.Columns.Add (bound);

			dg.DataBind ();

			LinkButton lb = (LinkButton) FindByType (dg.Controls [0], typeof (LinkButton));
			Assert.IsNotNull (lb, "lb");
			StringWriter sr = new StringWriter ();
			HtmlTextWriter output = new HtmlTextWriter (sr);
			Assert.AreEqual (Color.Empty, lb.ControlStyle.ForeColor, "fore");
			lb.RenderControl (output);
			Assert.AreEqual (Color.Empty, lb.ControlStyle.ForeColor, "fore2");
			string str = dg.Render ();
			Assert.IsTrue (-1 != str.IndexOf ("<a>Item 1</a>"), "item1");
			Assert.IsTrue (-1 != str.IndexOf ("<td>Item 1</td>"), "item1-2");
		}
		public void SelectIndexOutOfRange ()
		{
			DataGridPoker p = new DataGridPoker ();

			// No exception is thrown
			p.SelectedIndex = 25;
		}
		public void TagName ()
		{
			DataGridPoker p = new DataGridPoker ();
			Assert.AreEqual (p.GetTagName (), "table", "A1");
		}
		public void ControlStyle ()
		{
			DataGridPoker p = new DataGridPoker ();

			Assert.AreEqual (p.ControlStyle ().GetType (),
					typeof (TableStyle), "A1");

			TableStyle t = (TableStyle) p.ControlStyle ();
			Assert.AreEqual (t.GridLines, GridLines.Both, "A2");
			Assert.AreEqual (t.CellSpacing, 0, "A3");
		}
		public void NullBackImage ()
		{
			DataGridPoker p = new DataGridPoker ();

			p.BackImageUrl = null;
			Assert.AreEqual (p.BackImageUrl, String.Empty, "A1");
		}
		public void Events ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataGridCommandEventArgs command_args = new DataGridCommandEventArgs (null,
					null, new CommandEventArgs (String.Empty, String.Empty));
			DataGridItemEventArgs item_args = new DataGridItemEventArgs (null);
			DataGridPageChangedEventArgs page_args = new DataGridPageChangedEventArgs (null, 0);
			DataGridSortCommandEventArgs sort_args = new DataGridSortCommandEventArgs (null,
					command_args);

			ResetEvents ();
			p.CancelCommand += new DataGridCommandEventHandler (CancelCommandHandler);
			p.DoCancelCommand (command_args);
			Assert.IsTrue (cancel_command, "A1");

			ResetEvents ();
			p.DeleteCommand += new DataGridCommandEventHandler (DeleteCommandHandler);
			p.DoDeleteCommand (command_args);
			Assert.IsTrue (delete_command, "A2");

			ResetEvents ();
			p.EditCommand += new DataGridCommandEventHandler (EditCommandHandler);
			p.DoEditCommand (command_args);
			Assert.IsTrue (edit_command, "A3");

			ResetEvents ();
			p.ItemCommand += new DataGridCommandEventHandler (ItemCommandHandler);
			p.DoItemCommand (command_args);
			Assert.IsTrue (item_command, "A4");

			ResetEvents ();
			p.UpdateCommand += new DataGridCommandEventHandler (UpdateCommandHandler);
			p.DoUpdateCommand (command_args);
			Assert.IsTrue (update_command, "A5");

			ResetEvents ();
			p.ItemCreated += new DataGridItemEventHandler (ItemCreatedHandler);
			p.DoItemCreated (item_args);
			Assert.IsTrue (item_created, "A6");

			ResetEvents ();
			p.ItemDataBound += new DataGridItemEventHandler (ItemDataBoundHandler);
			p.DoItemDataBound (item_args);
			Assert.IsTrue (item_data_bound, "A7");

			ResetEvents ();
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoPageIndexChanged (page_args);
			Assert.IsTrue (page_index_changed, "A8");

			ResetEvents ();
			p.SortCommand += new DataGridSortCommandEventHandler (SortCommandHandler);
			p.DoSortCommand (sort_args);
			Assert.IsTrue (sort_command, "A9");
		}
		public void CleanProperties ()
		{
			DataGridPoker p = new DataGridPoker ();

			p.AllowCustomPaging = true;
			Assert.IsTrue (p.AllowCustomPaging, "A1");
			p.AllowCustomPaging = false;
			Assert.IsFalse (p.AllowCustomPaging, "A2");

			p.AllowPaging = true;
			Assert.IsTrue (p.AllowPaging, "A3");
			p.AllowPaging = false;
			Assert.IsFalse (p.AllowPaging, "A4");

			p.AllowSorting = true;
			Assert.IsTrue (p.AllowSorting, "A5");
			p.AllowSorting = false;
			Assert.IsFalse (p.AllowSorting, "A6");

			p.AutoGenerateColumns = true;
			Assert.IsTrue (p.AutoGenerateColumns, "A7");
			p.AutoGenerateColumns = false;
			Assert.IsFalse (p.AutoGenerateColumns, "A8");

			p.BackImageUrl = "foobar";
			Assert.AreEqual (p.BackImageUrl, "foobar", "A9");

			p.CurrentPageIndex = 0;
			Assert.AreEqual (p.CurrentPageIndex, 0, "A10");
			p.CurrentPageIndex = Int32.MaxValue;
			Assert.AreEqual (p.CurrentPageIndex, Int32.MaxValue, "A11");

			p.EditItemIndex = 0;
			Assert.AreEqual (p.EditItemIndex, 0, "A12");
			p.EditItemIndex = -1;
			Assert.AreEqual (p.EditItemIndex, -1, "A13");
			p.EditItemIndex = Int32.MaxValue;
			Assert.AreEqual (p.EditItemIndex, Int32.MaxValue, "A14");

			p.PageSize = 1;
			Assert.AreEqual (p.PageSize, 1, "A15");
			p.PageSize = Int32.MaxValue;

			p.SelectedIndex = 0;
			Assert.AreEqual (p.SelectedIndex, 0, "A16");
			p.SelectedIndex = -1;
			Assert.AreEqual (p.SelectedIndex, -1, "A17");
			p.SelectedIndex = Int32.MaxValue;
			Assert.AreEqual (p.SelectedIndex, Int32.MaxValue, "A18");

			p.ShowFooter = true;
			Assert.IsTrue (p.ShowFooter, "A19");
			p.ShowFooter = false;
			Assert.IsFalse (p.ShowFooter, "A20");

			p.ShowHeader = true;
			Assert.IsTrue (p.ShowHeader, "A21");
			p.ShowHeader = false;
			Assert.IsFalse (p.ShowHeader, "A22");

			p.VirtualItemCount = 0;
			Assert.AreEqual (p.VirtualItemCount, 0, "A23");
			p.VirtualItemCount = Int32.MaxValue;
			Assert.AreEqual (p.VirtualItemCount, Int32.MaxValue, "A24");
		}
		public void BubblePageCommand ()
		{
			DataGridPoker p = new DataGridPoker ();
			DataGridItem item = new DataGridItem (0, 0, ListItemType.Item);
			DataGridCommandEventArgs command_args;


			//
			// Prev
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Page", "Prev"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A1");
			Assert.AreEqual (new_page_index, 9, "A2");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("page", "prev"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A3");
			Assert.AreEqual (new_page_index, 9, "A4");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("PAGE", "PREV"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A5");
			Assert.AreEqual (new_page_index, 9, "A6");

			
			//
			// Next
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Page", "Next"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A5");
			Assert.AreEqual (new_page_index, 11, "A6");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("page", "next"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A7");
			Assert.AreEqual (new_page_index, 11, "A8");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("PAGE", "NEXT"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A9");
			Assert.AreEqual (new_page_index, 11, "A10");


			//
			// Specific
			//
			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Page", "25"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A11");
			Assert.AreEqual (new_page_index, 24, "A12");

			ResetEvents ();
			command_args = new DataGridCommandEventArgs (item, null,
					new CommandEventArgs ("Page", "0"));
			p.CurrentPageIndex = 10;
			p.PageIndexChanged += new DataGridPageChangedEventHandler (PageIndexChangedHandler);
			p.DoBubbleEvent (this, command_args);
			Assert.IsTrue (page_index_changed, "A11");
			Assert.AreEqual (new_page_index, -1, "A12");
		}
		public void CurrentPageIndexTooLow ()
		{
			DataGridPoker p = new DataGridPoker ();
			p.CurrentPageIndex = -1;
		}
		public void SaveViewState ()
		{
			DataGridPoker p = new DataGridPoker ();

			p.TrackState ();

			object [] vs = (object []) p.SaveState ();
			Assert.AreEqual (vs.Length, 11, "A1");

			// By default the viewstate is all null
			for (int i = 0; i < vs.Length; i++)
				Assert.IsNull (vs [i], "A2-" + i);

			//
			// TODO: What goes in the [1] and [9] slots?
			//

			p.AllowPaging = true;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [0], "A3");

			/*
			  This test doesn't work right now. It must be an issue
			  in the DataGridPagerStyle
			  
			p.PagerStyle.Visible = true;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [2], "A5");
			*/
			
			p.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [3], "A6");

			p.FooterStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [4], "A7");

			p.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [5], "A8");

			p.AlternatingItemStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [6], "A9");

			p.SelectedItemStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [7], "A10");

			p.EditItemStyle.HorizontalAlign = HorizontalAlign.Center;
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [8], "A11");

			PagedDataSource source = new PagedDataSource ();
			DataTable table = new DataTable ();
			ArrayList columns;

			table.Columns.Add (new DataColumn ("one", typeof (string)));
			table.Columns.Add (new DataColumn ("two", typeof (string)));
			table.Columns.Add (new DataColumn ("three", typeof (string)));
			source.DataSource = new DataView (table);
			columns = p.CreateColumns (source, true);

			vs = (object []) p.SaveState ();
			Assert.IsNull (vs [9], "A12");
			p.BackImageUrl = "foobar url";
			vs = (object []) p.SaveState ();
			Assert.IsNotNull (vs [9], "A12");

			Assert.IsNotNull (vs [10], "A12");
			Assert.AreEqual (vs [10].GetType (), typeof (object []), "A12");

			object [] cols = (object []) vs [10];
			Assert.AreEqual (cols.Length, 3, "A13");
		}
		public void DataSourceIDBindingNoColumns () 
		{
			Page page = new Page ();
			DataGridPoker dg = new DataGridPoker ();
			dg.ID = "DataGrid";
			dg.AutoGenerateColumns = false;

			page.Controls.Add (dg);

			ObjectDataSource ds = new ObjectDataSource ();
			ds.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
			ds.SelectMethod = "GetList";
			ds.SortParameterName = "sortExpression";
			ds.ID = "Data";
			page.Controls.Add (ds);

			dg.DataSourceID = "Data";
			dg.DataBind ();

			Assert.AreEqual (0, dg.Columns.Count, "Columns Count");
			Assert.AreEqual (0, dg.Items.Count, "Items Count");
		}