may be this will help you..
i am considering that you have a Database table named as
"Columns" whose data and structure is
col_id ----- col_name ---- opt_ID
______ _________ ________
lbl1 --------- Asp ---------- 1
lbl2 ------ --- C# ---------- 2
lbl3 --------- VB ---------- 22
lbl4 --------- Ado --------- 13
and as you said you have the Labels in on you web Page...
suppose you have assigned that Labels in a Container Control say Panel as
'panel1' as id....
and you have set your Labels ids as in the Database table
"Columns" column "col_id"...
now here is the Code..
var labels = from Control c in panel1.Controls where c.GetType().Equals(typeof(Label)) select c;
con.Open();
cmd = new SqlCommand("select col_id,col_name from Columns where opt_ID=@p_opt_id ", con);
cmd.Parameters.AddWithValue("@p_opt_id", p_opt_id);
rd = cmd.ExecuteReader();
while (rd.Read())
{
foreach(Control c in labels)
{
Label l = (Label)c;
if(l!=null)
{
if(l.id==rd["col_id"].ToString())
l.Text=rd["col_name"].ToString();
}
}
}
and to set the ID's of your Labels in Your Panel "panel1"..
use the "ID" Property of Label Control that can be set and get....
as...
Label1.ID="lbl1";
and i dont know what is "unsafe" in your code....
hope this will help you
may be i am answering quite irrelevant....
if so, sorry friends......