I am creating ASP.NET wep page. I have a world map and I want to add some image buttons (cities) controls in C#. I made the method:
I am using stored procedure to get data from database but when I add next city to the procedure the previously added imagebutton changes its position.
private void LocateCities()
{
IDBManager dbManager = new DBManager(DataProvider.SqlServer);
dbManager.ConnectionString = @"Data Source=server; Initial Catalog=db; Integrated Security = SSPI;";
try
{
dbManager.Open();
dbManager.CreateParameters(2);
dbManager.AddParameters(0, "@Function", "All");
dbManager.AddParameters(1, "@Team", "All");
DataSet ds = new DataSet("Stuff");
ds = dbManager.ExecuteDataSet(CommandType.StoredProcedure, "sp_select_staff_and_cities");
foreach (DataRow dr in ds.Tables[0].Rows)
{
int xaxis = Convert.ToInt32(dr["xaxis"]) ;
int yaxis = Convert.ToInt32(dr["yaxis"]) ;
int textxaxis = xaxis + 30;
int textyaxis = yaxis - 10;
ImageButton btnCity = new ImageButton();
btnCity.ImageUrl = "~/Images/cyanball1.gif";
btnCity.Height = 10;
btnCity.Attributes.Add("style", "Z-INDEX:100; POSITION:relative; left:" + xaxis + "px; TOP:" + yaxis + "px; Left:10px;Right:10px");
Label lblCity = new Label();
lblCity.Text = dr["city"].ToString();
lblCity.Attributes.Add("style", "Z-INDEX: 100;POSITION:relative; left:" + textxaxis + "px; TOP:" + textyaxis + "px");
PanelMap.Controls.Add(lblCity);
PanelMap.Controls.Add(btnCity);
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
dbManager.Dispose();
}
}
I am using panel to keep image with map: .PanelMap { width:960px; height:572px; text-align:left; }
What should be changed in above code to keep the points in its place?
I tried to use position:absolute but it cause that posiotion is derived relative to the page and I would like it would be derived relatively to the panel control.
System.Web.UI.HtmlControls.HtmlGenericControl("div")as a wrapper to your label and button