Here's the code
public class GeoEdit : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.Label lblX;
protected System.Web.UI.WebControls.Label lblY;
protected System.Web.UI.WebControls.Label lblBtnClicked;
protected dbTier dbt = new dbTier();
private int curX, curY, gridSize;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Session["curX"] = 400;
Session["curY"] = 300;
Session["gridSize"] = 11;
drawGeo();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btn_Command(object sender, CommandEventArgs e)
{
string[] cellIndex = e.CommandArgument.ToString().Split(new char[] {';'});
lblBtnClicked.Text = "CellClicked";
curX = int.Parse(cellIndex[0]);
curY = int.Parse(cellIndex[1]);
lblX.Text = "Row: " + curX.ToString();
lblY.Text = "Col: " + curY.ToString();
Session["curX"] = curX;
Session["curY"] = curY;
drawGeo();
}
private void drawGeo()
{
curX = (int)Session["curX"];
curY = (int)Session["curY"];
gridSize = (int)Session["gridSize"];
// calculate player location info
int gridShift = gridSize / 2; // ignore remainder
int x1 = curX - gridShift;
int x2 = curX + gridShift;
int y1 = curY - gridShift;
int y2 = curY + gridShift;
lblX.Text = "X: " + curX;
lblY.Text = "Y: " + curY;
// Get Geo info
// DataTable dtGeo = dbt.getGeo(x1, x2, y1, y2);
for (int rowIndex = y1; rowIndex <= y2; rowIndex++)
{
TableRow tr = new TableRow();
Table1.Rows.Add(tr);
for (int colIndex = x1; colIndex <= x2; colIndex++)
{
TableCell tc = new TableCell();
tr.Cells.Add(tc);
Button btn = new Button();
tc.Controls.Add(btn);
btn.CausesValidation = true;
btn.Text = rowIndex.ToString() + ";" + colIndex.ToString();
btn.CommandArgument = rowIndex.ToString() + ";" + colIndex.ToString();
btn.Command += new CommandEventHandler(btn_Command);
}
}
}
}
avnrao said:
how r u dynamically creating the buttons?
if you are using Button bt = new Button() code in your codebehind file,
you
can very well create a delegate and add it to the click event.
you can post your code for us to understand the problem better.
Av.