You need to use Control.FindControl("id") method to access the object by passing the id.
if (!IsPostBack)
{
for (int b =23; b < 100;b++ )
{
conn.Open();
cmd = new SqlCommand("select * from tbl_plotdetails where plotdetails_id='" + b + "' and status='vacant' ", conn);
dr = cmd.ExecuteReader();
dr.Read();
Control control=null;
if (dr.HasRows)
{
int a = b;
string d = "G" + a;
control = Page.FindControl(d);
control.Style.Add("border-color", "black");
dr.Close();
}
else
{
G23.Visible = false;
}
conn.Close();
}
}