|
Hi, I am trying to make a sudoku game but have run into a problem. basically i have a function to create the game view:
private void createView() { Table1.Rows.Clear(); for (int rowIndex = 0; rowIndex < State.Board.GetLength(0); rowIndex++) {
TableRow row = new TableRow(); Table1.Rows.Add(row);
for (int columnIndex = 0; columnIndex < State.Board.GetLength(1); columnIndex++) { TableCell cell = new TableCell(); int value = State.Board[columnIndex, rowIndex];
if ((ActiveCell == null) || (ActiveCell.Row != columnIndex) || (ActiveCell.Column != rowIndex)) { string id = String.Format("BoardButton_{0}_{1}", columnIndex, rowIndex); if (value >= 10) { Image image = new Image(); image.ID = id; image.ImageUrl = "Images/" + value / 10 + ".jpg"; image.Height = image.Width = 60; cell.Controls.Add(image); } else { ImageButton button = new ImageButton(); button.ID = id; button.ImageUrl = "Images/0.gif"; button.Height = button.Width = 60; button.CommandArgument = String.Format("{0}:{1}", columnIndex, rowIndex); button.Click += new ImageClickEventHandler(button_Click); cell.Controls.Add(button); } } else { TextBox editTextBox = new TextBox(); editTextBox.ID = String.Format("BoardEditTextBox_{0}_{1}", columnIndex, rowIndex); editTextBox.Width = new Unit(30); cell.Controls.Add(editTextBox);
LinkButton editLinkButton = new LinkButton(); editLinkButton.ID = String.Format("BoardEditLinkButton_{0}_{1}", columnIndex, rowIndex); editLinkButton.Click += new EventHandler(editLinkButton_Click); editLinkButton.Text = ">>"; cell.Controls.Add(editLinkButton); } row.Cells.Add(cell); } } }
the code for the buttons are as follows:
void editLinkButton_Click(object sender, EventArgs e) { Control linkButton = sender as Control; TableCell cell = linkButton.Parent as TableCell; int x = ActiveCell.Row; int y = ActiveCell.Column; string find = String.Format("BoardEditTextBox_{0}_{1}", x, y); TextBox editBox = cell.FindControl(find) as TextBox; State.Board[x, y] = int.Parse(editBox.Text); ActiveCell = null; createView(); }
void button_Click(object sender, EventArgs e) { ImageButton button = sender as ImageButton; string[] xySplit = button.CommandArgument.Split(new char[] { ':' }); int x = int.Parse(xySplit[0]); int y = int.Parse(xySplit[1]); int value = int.Parse(State.Board[x, y].ToString()); this.ActiveCell = new BoardCell(x, y); button.ImageUrl = "Images/" + value + ".jpg"; createView(); }
when i number is typed in, the createview() is called and the imageurl is set to 0. i cant think of a way to set the imageurl to the number typed in?
any help would be much apreciated.
Thanks
Andy
|